Address review of host pairing

Revoking a host now unassigns its instances instead of being refused
while it has any, and removes its system metrics.

Approving and revoking no longer force a save. Hosts are saved by
autosave and on exit like everything else, which also removes the
approving state from pairing requests.

The approval code and link are logged as warnings so they show up in
the systemd service, which only prints warnings and above. The pairing
limits are now the controller.host_pairing_timeout and
controller.host_pairing_max_pending config values, 0 removes the limit.

Subscribers take an optional permitted function, used for the pairing
requests instead of overrides in a subclass.
This commit is contained in:
Danielv123 committed 2026-10-31 16:31:45 +01:00
1 parent e5701a8dae
commit 49a0b27d29
29 files changed
+356 -418

No files matched your search

+9 -11
View File
@@ -851,7 +851,7 @@ describe("Integration of Clusterio", function() {
assert(!notes.some(note => note.id === `host/${pairing.hostId}`), "Note of the host was not removed");
});
it("should refuse while instances are assigned to the host", async function() {
it("should unassign the instances of the host", async function() {
const pairing = await pairTestHost("assigned-host");
// Instances can only be assigned to connected hosts, a link that accepts the assignment is enough.
const connector = new TestHostConnector(url, 0.2);
@@ -863,19 +863,17 @@ describe("Integration of Clusterio", function() {
await execCtl("instance create revoke-assigned --id 45");
try {
await execCtl(`instance assign revoke-assigned ${pairing.hostId}`);
await assert.rejects(
execCtl(`host revoke ${pairing.hostId}`),
/Cannot revoke host assigned-host while instances are assigned to it: revoke-assigned/,
);
connector.setClosing(); // Stops it from reconnecting after being revoked
await execCtl(`host revoke ${pairing.hostId}`);
const hosts = await getControl().send(new lib.HostListRequest());
assert(!hosts.some(host => host.id === pairing.hostId), "Host was not removed");
const instance = await getControl().send(new lib.InstanceDetailsGetRequest(45));
assert.equal(instance.assignedHost, undefined);
assert.equal(instance.status, "unassigned");
} finally {
await connector.disconnect();
await execCtl("instance assign revoke-assigned");
await execCtl("instance delete revoke-assigned");
}
await execCtl(`host revoke ${pairing.hostId}`);
const hosts = await getControl().send(new lib.HostListRequest());
assert(!hosts.some(host => host.id === pairing.hostId), "Host was not removed");
});
it("should stop a running host and have it ask to join again when started", async function() {
+5 -8
View File
@@ -311,22 +311,19 @@ export function spawn(name, cmd, waitFor, options = {}) {
let process = child_process.spawn(parts[0], parts.slice(1), childOptions(options));
let stdout = new LineSplitter({ readableObjectMode: true });
let stderr = new LineSplitter({ readableObjectMode: true });
let onDataOut = line => {
let onData = line => {
line = line.toString("utf8");
if (waitFor.test(line)) {
if (silent) {
stdout.off("data", onDataOut);
stderr.off("data", onDataErr);
stdout.off("data", onData);
stderr.off("data", onData);
}
resolve(process);
}
log(name, line);
};
let onDataErr = line => {
log(name, line.toString("utf8"));
};
stdout.on("data", onDataOut);
stderr.on("data", onDataErr);
stdout.on("data", onData);
stderr.on("data", onData);
process.stdout.pipe(stdout);
process.stderr.pipe(stderr);
});