Fix OS detection in DirectorStemcellOwner to read from system files#2640
Merged
rkoster merged 1 commit intocloudfoundry:mainfrom Dec 4, 2025
Merged
Fix OS detection in DirectorStemcellOwner to read from system files#2640rkoster merged 1 commit intocloudfoundry:mainfrom
rkoster merged 1 commit intocloudfoundry:mainfrom
Conversation
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`
Contributor
There was a problem hiding this comment.
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
unameoutput with direct file system reads from/var/vcap/bosh/etc/operating_systemand/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.
selzoc
approved these changes
Dec 3, 2025
rkoster
approved these changes
Dec 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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 envoutput):Director Stemcell -/1.943After (
bosh envoutput):Director Stemcell ubuntu-jammy/1.943What tests have you run against this PR?
bundle exec rake spec:unit:directorHow 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