Repository navigation
feat(serve): berth serve --simulate for testing against the API - #73
Merged
Merged
Conversation
Each host is a berthd in single-user mode in the scratch directory, and its commands run through a shell of a few canned commands. The plugin sim holds the provisioner sim/cloud, which berth runs itself.
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.
Adds a simulated berth server so applications can test against the real API in CI without machines, SSH, Ansible or a cloud account.
berth serve --simulate [--listen ADDR] [--seed FILE] [--delay SECONDS] [--data DIR] [--keep]runs the realberth serve(routes, roles, tokens, store, jobs, events, portal) on a scratch directory. Only what would reach another machine is stood in for:Host::linkreturns it while a simulation runs). Its commands go through a small shell of canned commands. It lists and signals only its own processes, and it refuses ports. Until the first apply the link reports no berthd, as on a fresh machine.applied.json,profile.json, actions). After thatapply::settle_withruns as usual.simholdssim/cloud, with kindsmachine(setup apply) andservice. It runs asberth simulated-provisioner VERBthrough the ordinary plugin protocol, andprovision::Optionswaits for nothing.resources.connectrefuses every endpoint.It is marked everywhere: a
berth-simulated: 1header on every answer,"simulated": truein the server's and each host'sversion, and simulated in the screens' header.State goes in a new directory under
TMPDIR, removed on Ctrl+C or SIGTERM.XDG_*are pointed into it for the process and what it starts, so it never touches the user's own configuration or socket.--datarefuses berth's own directories and any directory that holds something else.BERTH_SIMULATE=1andBERTH_SIMULATE_SEEDturn the published image into a simulated server, because GitHub Actions services cannot change the image's command.Docs:
docs/content/docs/api/testing.mdxcovers starting it, the seed format, what is real and what is simulated, timings and a GitHub Actionsservices:example.Tests:
crates/berth/tests/simulate.rsstarts the built berth with a seed and goes through a host's whole life: token login, create throughsim/cloud, apply, an action, a session through the portal, stop/start, removal, events through the portal, cleanup on exit. Unit tests cover seed parsing, refusal of the user's own and foreign directories, and the provisioner's states.Not run here: the container end-to-end shards and an image build (the disk was nearly full), and the Windows and macOS checks (
ringneeds a cross C toolchain this machine lacks). The client-side changes are platform-neutral or behindcfg(target_os = "linux").