Repository navigation
fix(rootfs): boot with the assembled hostname, not a literal "eos" - #198
harshini-5040 wants to merge 1 commit into
Conversation
assemble(hostname=...) writes the name to /etc/hostname and /etc/hosts, but rcS ran "hostname eos" at boot. The board build assembles with hostname "eos-<board>", so those images booted as "eos" -- a name their own /etc/hosts does not resolve. rcS now sets the hostname from /etc/hostname and falls back to "eos" only when that file is absent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideImplementationUpdate generated rcS to set the assembled hostname from
DocumentationDocument the hostname mismatch and its fix in the changelog.
TestsAdd tests covering hostname selection from
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
You've used all your free Kodus-paid PR reviews 🎁Your trial is still active — this just means the PR reviews we cover during the trial are used up. Connect your own AI key to keep Kody reviewing — unlimited reviews, on any plan (Free included). Want more trial reviews to finish evaluating before adding a key? Talk to our founders. 😎 |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 6 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="ebuild/system/rootfs.py" line_range="144" />
<code_context>
- "hostname eos\n"
+ # configure_network() writes the assembled hostname here; "eos"
+ # only if it is absent (install_init() used on its own).
+ "[ -s /etc/hostname ] && hostname -F /etc/hostname || hostname eos\n"
"echo 'EoS booted successfully'\n"
)
</code_context>
<issue_to_address>
**Configured hostname gets replaced**
When `/etc/hostname` is non-empty and `hostname -F /etc/hostname` exits nonzero, the `|| hostname eos` branch in `rcS` masks the load failure and continues booting with `eos`, even though `/etc/hostname` and `/etc/hosts` name the configured host.
Use `eos` only when `/etc/hostname` is absent or empty, and let a failed hostname load remain an error.
</issue_to_address>
### Comment 2
<location path="tests/unit/test_rootfs_hostname.py" line_range="27" />
<code_context>
+ assert (rootfs / "etc" / "hostname").read_text() == "eos-rpi4\n"
+ rcs_lines = _rcs(rootfs).splitlines()
+ assert "hostname eos" not in rcs_lines
+ assert any("hostname -F /etc/hostname" in line for line in rcs_lines)
+
+
</code_context>
<issue_to_address>
**Hostname tests only inspect script text**
When rcS contains the expected command text in a non-executing or incorrectly branched command, `test_rcs_sets_the_hostname_from_etc_hostname` (line 27) and `test_rcs_keeps_eos_as_the_fallback_without_etc_hostname` (lines 38–39) only look for command strings. A broken rcS line such as `[ -s /etc/hostname ] && echo hostname -F /etc/hostname || hostname eos` satisfies both checks but never sets the configured hostname, so the tests pass while the bug remains.
Run the generated rcS under a shell with a stub `hostname` and assert which arguments are invoked for present and absent hostname files.
Also at `tests/unit/test_rootfs_hostname.py:38-39`.
</issue_to_address>Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: ebuild/system/rootfs.py:144, tests/unit/test_rootfs_hostname.py:27
| "hostname eos\n" | ||
| # configure_network() writes the assembled hostname here; "eos" | ||
| # only if it is absent (install_init() used on its own). | ||
| "[ -s /etc/hostname ] && hostname -F /etc/hostname || hostname eos\n" |
There was a problem hiding this comment.
🟡 Medium · Configured hostname gets replaced
When /etc/hostname is non-empty and hostname -F /etc/hostname exits nonzero, the || hostname eos branch in rcS masks the load failure and continues booting with eos, even though /etc/hostname and /etc/hosts name the configured host.
Use eos only when /etc/hostname is absent or empty, and let a failed hostname load remain an error.
Prompt for AI agents
In `ebuild/system/rootfs.py` at line 144:
**Configured hostname gets replaced**
When `/etc/hostname` is non-empty and `hostname -F /etc/hostname` exits nonzero, the `|| hostname eos` branch in `rcS` masks the load failure and continues booting with `eos`, even though `/etc/hostname` and `/etc/hosts` name the configured host.
Use `eos` only when `/etc/hostname` is absent or empty, and let a failed hostname load remain an error.From QUALITY.md L37-38:
- Never fail silently. A swallowed error is a defect that will be found later
and cost more.| assert (rootfs / "etc" / "hostname").read_text() == "eos-rpi4\n" | ||
| rcs_lines = _rcs(rootfs).splitlines() | ||
| assert "hostname eos" not in rcs_lines | ||
| assert any("hostname -F /etc/hostname" in line for line in rcs_lines) |
There was a problem hiding this comment.
🟡 Medium · Hostname tests only inspect script text
When rcS contains the expected command text in a non-executing or incorrectly branched command, test_rcs_sets_the_hostname_from_etc_hostname (line 27) and test_rcs_keeps_eos_as_the_fallback_without_etc_hostname (lines 38–39) only look for command strings. A broken rcS line such as [ -s /etc/hostname ] && echo hostname -F /etc/hostname || hostname eos satisfies both checks but never sets the configured hostname, so the tests pass while the bug remains.
Run the generated rcS under a shell with a stub hostname and assert which arguments are invoked for present and absent hostname files.
Also at tests/unit/test_rootfs_hostname.py:38-39.
Prompt for AI agents
In `tests/unit/test_rootfs_hostname.py` at line 27:
**Hostname tests only inspect script text**
When rcS contains the expected command text in a non-executing or incorrectly branched command, `test_rcs_sets_the_hostname_from_etc_hostname` (line 27) and `test_rcs_keeps_eos_as_the_fallback_without_etc_hostname` (lines 38–39) only look for command strings. A broken rcS line such as `[ -s /etc/hostname ] && echo hostname -F /etc/hostname || hostname eos` satisfies both checks but never sets the configured hostname, so the tests pass while the bug remains.
Run the generated rcS under a shell with a stub `hostname` and assert which arguments are invoked for present and absent hostname files.
Also at `tests/unit/test_rootfs_hostname.py:38-39`.
Linked issuesChecked at commit 0613251 #224 Rootfs boots with a literal "eos" hostname instead of the assembled one · 1 of 1 met
|
|
Held for rebase: this PR is in merge conflict with current master (9f49ca8) — the conflict is the shared CHANGELOG.md entry, which PR #195 also edited when it merged today. The source files do not overlap any merged PR, and premise + CI both passed on the current head, so this is merge-ready once rebased. Please rebase onto master, resolve the CHANGELOG conflict (keep both entries), and push — CI will re-run and the PR returns to the next merge train. — av_mando |
Bug
RootfsBuilder.assemble(hostname=...)writes the hostname to/etc/hostnameand/etc/hosts, but the generated/etc/init.d/rcSran a literalhostname eosat boot. The board build callsassemble(hostname="eos-" + board.lower())(ebuild/cli/commands.py), so for example anrpi4image haseos-rpi4in/etc/hostnameand/etc/hostsbut boots aseos. Its own/etc/hostsdoes not resolve that name, which leads to errors like "unable to resolve host" from tools such assudo.Root cause
install_init()wrote the rcS script with a hard-coded hostname. It ignored the value thatconfigure_network()writes to/etc/hostname.Fix
One line of rcS changes from:
to:
BusyBox
hostnamesupports-F FILE. Theeosfallback keeps the previous behaviour wheninstall_init()is used withoutconfigure_network(), or when/etc/hostnameis empty. No signature or API changes.Reproduction
/etc/hostnamecontainseos-rpi4, but rcS runshostname eos./etc/hostname.Tests
New file
tests/unit/test_rootfs_hostname.pywith 2 tests: rcS takes the hostname from/etc/hostname, and theeosfallback still applies wheninstall_init()is used on its own.test_rootfs_accounts.pygive 30 passed.shwith a stubhostnamefunction: it ranhostname -F <file>when the file existed andhostname eoswhen it did not.--ignore=tests/unit/test_hardware_validation_gate.py): 995 passed, 25 skipped, 3 failed. Onmasterwithout this change: 993 passed, 25 skipped, and the same 3 failed. Those 3 are environment-only:jsonschemais not installed andgccis not on PATH.git diff --check: clean.Not tested: booting a real image on BusyBox.
🤖 Generated with Claude Code
Summary by Sourcery
Boot assembled root filesystems with their configured hostname instead of a hard-coded name.
Bug Fixes:
/etc/hostname, while retainingeosas a fallback when no hostname is configured.Tests:
install_init()fallback.Closes #224