Skip to content

Conversation

@s4heid
Copy link
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`
@aramprice aramprice requested review from a team, selzoc and ystros and removed request for a team November 13, 2025 16:06
@aramprice aramprice moved this from Inbox to Pending Review | Discussion in Foundational Infrastructure Working Group Nov 13, 2025
@rkoster rkoster requested a review from Copilot November 27, 2025 15:40
Copilot finished reviewing on behalf of rkoster November 27, 2025 15:42
Copy link
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.

Comment on lines +37 to +41
File.readlines(OS_RELEASE_FILE).each do |line|
if line =~ /^ID=(.+)$/
return ::Regexp.last_match(1).strip.delete('"').downcase
end
end
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The File.readlines call could raise exceptions (e.g., Errno::ENOENT, Errno::EACCES) if the file becomes inaccessible between the existence check and the read. Consider wrapping this in a rescue block to return nil on error, similar to how stemcell_version handles the file read.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +53
File.readlines(OS_RELEASE_FILE).each do |line|
if line =~ /^UBUNTU_CODENAME=(.+)$/
return ::Regexp.last_match(1).strip.delete('"')
end
end
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The File.readlines call could raise exceptions (e.g., Errno::ENOENT, Errno::EACCES) if the file becomes inaccessible between the existence check and the read. Consider wrapping this in a rescue block to return nil on error, similar to how stemcell_version handles the file read.

Copilot uses AI. Check for mistakes.

def read_operating_system
if File.exist?(OPERATING_SYSTEM_FILE)
return File.read(OPERATING_SYSTEM_FILE).chomp.downcase
Copy link

Copilot AI Nov 27, 2025

Choose a reason for hiding this comment

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

The File.read call could raise exceptions (e.g., Errno::ENOENT, Errno::EACCES) if the file becomes inaccessible between the existence check and the read. Consider wrapping this in a rescue block to return nil on error, similar to how stemcell_version handles the file read.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending Review | Discussion

Development

Successfully merging this pull request may close these issues.

1 participant