Skip to content

Return /etc/hostname when 'hostname' command does not exist#642

Merged
bartlettroscoe merged 2 commits intoTriBITSPub:masterfrom
bartlettroscoe:etc-hostname
Feb 2, 2026
Merged

Return /etc/hostname when 'hostname' command does not exist#642
bartlettroscoe merged 2 commits intoTriBITSPub:masterfrom
bartlettroscoe:etc-hostname

Conversation

@bartlettroscoe
Copy link
Copy Markdown
Member

In the Trilinos clang container, the command 'hostname' does not exist but the file /etc/hostname does exist.

In the Trilinos clang container, the command 'hostname' does not exist but the
file /etc/hostname does exist.
Copy link
Copy Markdown

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

Adjusts hostname detection for CI containers where the hostname executable is missing by adding a fallback mechanism.

Changes:

  • Wraps hostname command execution in exception handling.
  • Falls back to retrieving hostname via /etc/hostname when the command fails/returns empty.

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

Comment thread tribits/ci_support/CheckinTest.py Outdated
Comment on lines +166 to +171
if hostname == "":
try:
hostname = getCmndOutput("cat /etc/hostname", True)
except Exception:
pass
return hostname
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

If both the hostname command and /etc/hostname fallback fail, this now returns an empty string. That propagates into email subjects/bodies (e.g., "...: %s: %s"), producing blank hostnames and making messages harder to interpret. Consider returning a clear sentinel like "unknown" (or using socket.gethostname() as a final fallback) instead of "".

Copilot uses AI. Check for mistakes.
Comment on lines +164 to +169
except Exception:
pass
if hostname == "":
try:
hostname = getCmndOutput("cat /etc/hostname", True)
except Exception:
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

Catching Exception and silently pass will also swallow unexpected failures (e.g., coding errors, KeyboardInterrupt), making debugging hard. Prefer calling getCmndOutput(..., throwOnError=False) or only catching RuntimeError from getCmndOutput and handling that explicitly (optionally with a minimal fallback value).

Suggested change
except Exception:
pass
if hostname == "":
try:
hostname = getCmndOutput("cat /etc/hostname", True)
except Exception:
except RuntimeError:
pass
if hostname == "":
try:
hostname = getCmndOutput("cat /etc/hostname", True)
except RuntimeError:

Copilot uses AI. Check for mistakes.
@bartlettroscoe
Copy link
Copy Markdown
Member Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown
Collaborator

@rabartlett1972 rabartlett1972 left a comment

Choose a reason for hiding this comment

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

I tested manually in my Trilinos clang container and this passed. In that container, the hostname command does not exist.

@bartlettroscoe bartlettroscoe merged commit cf6f9ec into TriBITSPub:master Feb 2, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants