Rename Slave to Host

The role of a slave as a host for Factorio servers is not well reflected
in its name and has caused confusion among users.  Rename slave to host
to better reflect its role as a host of Factorio servers.
This commit is contained in:
Hornwitser committed 2023-02-22 15:30:51 +01:00
1 parent 70ad295a89
commit 6fc3abafd5
101 files changed
+1168 -1168

No files matched your search

+1 -1
View File
@@ -307,7 +307,7 @@ describe("controller/src/routes", function() {
});
assert.equal(response.statusCode, 500);
assert.deepEqual(
JSON.parse(response.body), { errors: ["Timed out establishing stream to slave"], request_errors: [] }
JSON.parse(response.body), { errors: ["Timed out establishing stream to host"], request_errors: [] }
);
});
+6 -6
View File
@@ -1,9 +1,9 @@
{"timestamp":"2021-12-10T10:00:00.000Z","level":"verbose","message":"Controller start"}
{"timestamp":"2021-12-10T10:00:01.000Z","level":"verbose","message":"Loading"}
{"timestamp":"2021-12-10T10:00:03.000Z","level":"info","message":"Ready"}
{"timestamp":"2021-12-10T10:00:10.000Z","slave_id":1,"level":"verbose","message":"Slave connected"}
{"timestamp":"2021-12-10T10:00:11.000Z","slave_id":1,"level":"verbose","message":"Found instance 10"}
{"timestamp":"2021-12-10T10:00:13.000Z","slave_id":1,"instance_id":10,"level":"server","message":"Starting up"}
{"timestamp":"2021-12-10T10:00:14.000Z","slave_id":1,"instance_id":10,"level":"server","message":"Loading map"}
{"timestamp":"2021-12-10T10:00:15.000Z","slave_id":1,"instance_id":10,"level":"server","message":"Game ready"}
{"timestamp":"2021-12-10T10:01:00.000Z","slave_id":1,"instance_id":10,"level":"error","message":"Unexpected crash"}
{"timestamp":"2021-12-10T10:00:10.000Z","host_id":1,"level":"verbose","message":"Host connected"}
{"timestamp":"2021-12-10T10:00:11.000Z","host_id":1,"level":"verbose","message":"Found instance 10"}
{"timestamp":"2021-12-10T10:00:13.000Z","host_id":1,"instance_id":10,"level":"server","message":"Starting up"}
{"timestamp":"2021-12-10T10:00:14.000Z","host_id":1,"instance_id":10,"level":"server","message":"Loading map"}
{"timestamp":"2021-12-10T10:00:15.000Z","host_id":1,"instance_id":10,"level":"server","message":"Game ready"}
{"timestamp":"2021-12-10T10:01:00.000Z","host_id":1,"instance_id":10,"level":"error","message":"Unexpected crash"}
+26 -26
View File
@@ -3,9 +3,9 @@ const assert = require("assert").strict;
const path = require("path");
const libConfig = require("@clusterio/lib/config");
const Slave = require("@clusterio/slave/src/Slave");
const Host = require("@clusterio/host/src/Host");
describe("Slave testing", function() {
describe("Host testing", function() {
before(function() {
libConfig.InstanceConfig.finalize();
});
@@ -13,9 +13,9 @@ describe("Slave testing", function() {
describe("discoverInstances()", function() {
it("should discover test instance", async function() {
let instancePath = path.join("test", "file", "instances");
let instanceInfos = await Slave._discoverInstances(instancePath);
let instanceInfos = await Host._discoverInstances(instancePath);
let referenceConfig = new libConfig.InstanceConfig("slave");
let referenceConfig = new libConfig.InstanceConfig("host");
await referenceConfig.init();
referenceConfig.set("instance.id", 1);
referenceConfig.set("instance.name", "test");
@@ -29,11 +29,11 @@ describe("Slave testing", function() {
});
});
describe("class Slave", function() {
describe("class Host", function() {
describe(".syncUserListsEventHandler()", function() {
let mockSlave;
let mockHost;
beforeEach(function() {
mockSlave = {
mockHost = {
adminlist: new Set(),
whitelist: new Set(),
banlist: new Map(),
@@ -41,7 +41,7 @@ describe("Slave testing", function() {
broadcastEventToInstance(message, event) {
this.broadcasts.push(message["data"]);
},
syncUserListsEventHandler: Slave.prototype.syncUserListsEventHandler,
syncUserListsEventHandler: Host.prototype.syncUserListsEventHandler,
syncLists(adminlist, banlist, whitelist) {
return this.syncUserListsEventHandler({ "data": {
"adminlist": adminlist,
@@ -53,57 +53,57 @@ describe("Slave testing", function() {
});
it("should broadcast new entries to adminlist", async function() {
await mockSlave.syncLists(["admin1"], [], []);
await mockSlave.syncLists(["admin1", "admin2"], [], []);
await mockHost.syncLists(["admin1"], [], []);
await mockHost.syncLists(["admin1", "admin2"], [], []);
assert.deepEqual(mockSlave.broadcasts, [
assert.deepEqual(mockHost.broadcasts, [
{ "name": "admin1", "admin": true },
{ "name": "admin2", "admin": true },
]);
});
it("should broadcast removals from adminlist", async function() {
mockSlave.adminlist.add("admin1").add("admin2");
await mockSlave.syncLists(["admin1"], [], []);
assert.deepEqual(mockSlave.broadcasts, [
mockHost.adminlist.add("admin1").add("admin2");
await mockHost.syncLists(["admin1"], [], []);
assert.deepEqual(mockHost.broadcasts, [
{ "name": "admin2", "admin": false },
]);
});
it("should broadcast new entries to whitelist", async function() {
await mockSlave.syncLists([], [], ["player1"]);
await mockSlave.syncLists([], [], ["player1", "player2"]);
await mockHost.syncLists([], [], ["player1"]);
await mockHost.syncLists([], [], ["player1", "player2"]);
assert.deepEqual(mockSlave.broadcasts, [
assert.deepEqual(mockHost.broadcasts, [
{ "name": "player1", "whitelisted": true },
{ "name": "player2", "whitelisted": true },
]);
});
it("should broadcast removals from whitelist", async function() {
mockSlave.whitelist.add("player1").add("player2");
await mockSlave.syncLists([], [], ["player1"]);
mockHost.whitelist.add("player1").add("player2");
await mockHost.syncLists([], [], ["player1"]);
assert.deepEqual(mockSlave.broadcasts, [
assert.deepEqual(mockHost.broadcasts, [
{ "name": "player2", "whitelisted": false },
]);
});
it("should broadcast new entries to banlist", async function() {
await mockSlave.syncLists([], [["badie1", "greifing"]], []);
await mockSlave.syncLists([], [["badie1", "greifing"], ["badie2", "annoying"]], []);
await mockHost.syncLists([], [["badie1", "greifing"]], []);
await mockHost.syncLists([], [["badie1", "greifing"], ["badie2", "annoying"]], []);
assert.deepEqual(mockSlave.broadcasts, [
assert.deepEqual(mockHost.broadcasts, [
{ "name": "badie1", "banned": true, "reason": "greifing" },
{ "name": "badie2", "banned": true, "reason": "annoying" },
]);
});
it("should broadcast removals to banlist", async function() {
mockSlave.banlist.set("badie1", "greifing").set("badie2", "annoying");
await mockSlave.syncLists([], [["badie1", "greifing"]], []);
mockHost.banlist.set("badie1", "greifing").set("badie2", "annoying");
await mockHost.syncLists([], [["badie1", "greifing"]], []);
assert.deepEqual(mockSlave.broadcasts, [
assert.deepEqual(mockHost.broadcasts, [
{ "name": "badie2", "banned": false, "reason": "" },
]);
});
@@ -4,7 +4,7 @@ const path = require("path");
const libConfig = require("@clusterio/lib/config");
const { wait } = require("@clusterio/lib/helpers");
const Instance = require("@clusterio/slave/src/Instance");
const Instance = require("@clusterio/host/src/Instance");
const { MockConnector, MockServer } = require("../mock");
@@ -16,7 +16,7 @@ describe("class Instance", function() {
let instance;
let connector;
beforeEach(async function() {
let instanceConfig = new libConfig.InstanceConfig("slave");
let instanceConfig = new libConfig.InstanceConfig("host");
await instanceConfig.init();
instanceConfig.set("instance.name", "foo");
connector = new MockConnector();
+44 -44
View File
@@ -92,7 +92,7 @@ describe("Integration of Clusterio", function() {
let result = await libLink.messages.queryLog.send(getControl(), {
all: true,
controller: false,
slave_ids: [],
host_ids: [],
instance_ids: [],
max_level: null,
limit: 10,
@@ -104,7 +104,7 @@ describe("Integration of Clusterio", function() {
let first = await libLink.messages.queryLog.send(getControl(), {
all: true,
controller: false,
slave_ids: [],
host_ids: [],
instance_ids: [],
max_level: null,
limit: 1,
@@ -113,7 +113,7 @@ describe("Integration of Clusterio", function() {
let last = await libLink.messages.queryLog.send(getControl(), {
all: true,
controller: false,
slave_ids: [],
host_ids: [],
instance_ids: [],
max_level: null,
limit: 1,
@@ -124,41 +124,41 @@ describe("Integration of Clusterio", function() {
});
});
describe("clusterioslave", function() {
describe("slaveUpdateEventHandler()", function() {
it("should trigger when a new slave is added", async function() {
// On windows there's currently no way to automate graceful shutdown of the slave
describe("clusteriohost", function() {
describe("hostUpdateEventHandler()", function() {
it("should trigger when a new host is added", async function() {
// On windows there's currently no way to automate graceful shutdown of the host
// process as CTRL+C is some weird terminal thing and SIGINT isn't a thing.
if (process.platform === "win32") {
this.skip();
}
slowTest(this);
getControl().slaveUpdates = [];
let config = "alt-slave-config.json";
getControl().hostUpdates = [];
let config = "alt-host-config.json";
let configPath = path.join("temp", "test", config);
await fs.remove(configPath);
await fs.remove(path.join("temp", "test", "alt-instances"));
await execCtl(`slave create-config --id 5 --name alt-slave --generate-token --output ${config}`);
await execCtl(`host create-config --id 5 --name alt-host --generate-token --output ${config}`);
await exec(
`node ../../packages/slave --config ${config} config set slave.tls_ca ../../test/file/tls/cert.pem`
`node ../../packages/host --config ${config} config set host.tls_ca ../../test/file/tls/cert.pem`
);
await exec(
`node ../../packages/slave --config ${config} config set slave.instances_directory alt-instances`
`node ../../packages/host --config ${config} config set host.instances_directory alt-instances`
);
let slaveProcess;
let hostProcess;
try {
slaveProcess = await spawn(
"alt-slave:", `node ../../packages/slave run --config ${config}`, /Started slave/
hostProcess = await spawn(
"alt-host:", `node ../../packages/host run --config ${config}`, /Started host/
);
// Add instance to test the unknown status afterwards
await execCtl("instance create alt-test --id 99");
await execCtl("instance assign alt-test 5");
} finally {
if (slaveProcess) {
slaveProcess.kill("SIGINT");
await events.once(slaveProcess, "exit");
if (hostProcess) {
hostProcess.kill("SIGINT");
await events.once(hostProcess, "exit");
}
}
@@ -166,8 +166,8 @@ describe("Integration of Clusterio", function() {
let sawConnected = false;
let sawDisconnected = false;
for (let update of getControl().slaveUpdates) {
if (update.name !== "alt-slave") {
for (let update of getControl().hostUpdates) {
if (update.name !== "alt-host") {
continue;
}
@@ -179,13 +179,13 @@ describe("Integration of Clusterio", function() {
}
}
assert(sawUpdate, "No slave update was sent");
assert(sawConnected, "No slave update with status connected was sent");
assert(sawDisconnected, "No slave update with status disconnected was sent");
assert(sawUpdate, "No host update was sent");
assert(sawConnected, "No host update with status connected was sent");
assert(sawDisconnected, "No host update with status disconnected was sent");
let result = await libLink.messages.listSlaves.send(getControl());
let slaves = new Map(result.list.map(instance => [instance.id, instance]));
assert(slaves.has(5), "Slave list was not updated");
let result = await libLink.messages.listHosts.send(getControl());
let hosts = new Map(result.list.map(instance => [instance.id, instance]));
assert(hosts.has(5), "Host list was not updated");
});
});
});
@@ -233,17 +233,17 @@ describe("Integration of Clusterio", function() {
});
});
describe("slave list", function() {
describe("host list", function() {
it("runs", async function() {
await execCtl("slave list");
await execCtl("host list");
});
});
describe("slave generate-token", function() {
describe("host generate-token", function() {
it("runs", async function() {
await execCtl("slave generate-token --id 42");
await execCtl("host generate-token --id 42");
});
it("runs without an id", async function() {
await execCtl("slave generate-token");
await execCtl("host generate-token");
});
});
describe("instance list", function() {
@@ -370,7 +370,7 @@ describe("Integration of Clusterio", function() {
let { log } = await libLink.messages.queryLog.send(getControl(), {
all: false,
controller: false,
slave_ids: [],
host_ids: [],
instance_ids: [44],
max_level: null,
limit: 10,
@@ -683,24 +683,24 @@ describe("Integration of Clusterio", function() {
;
describe(remote ? "remote" : "local", function() {
if (remote) {
let slaveProcess;
let hostProcess;
before(async function() {
// On windows there's currently no way to automate graceful shutdown of the slave
// On windows there's currently no way to automate graceful shutdown of the host
// process as CTRL+C is some weird terminal thing and SIGINT isn't a thing.
if (process.platform === "win32") {
this.skip();
}
slowTest(this);
// Reuse from the clusterioslave test
let config = "alt-slave-config.json";
slaveProcess = await spawn(
"alt-slave:", `node ../../packages/slave run --config ${config}`, /Started slave/
// Reuse from the clusteriohost test
let config = "alt-host-config.json";
hostProcess = await spawn(
"alt-host:", `node ../../packages/host run --config ${config}`, /Started host/
);
});
after(async function() {
if (slaveProcess) {
slaveProcess.kill("SIGINT");
await events.once(slaveProcess, "exit");
if (hostProcess) {
hostProcess.kill("SIGINT");
await events.once(hostProcess, "exit");
}
});
}
@@ -1036,14 +1036,14 @@ describe("Integration of Clusterio", function() {
assert.deepEqual(newRole, { id: 5, name: "new", description: "A new role", permissions: [] });
});
it("should add permissions with --add-perms", async function() {
let args = "--name new --add-perms core.slave.list core.instance.list";
let args = "--name new --add-perms core.host.list core.instance.list";
await execCtl(`role edit new ${args}`);
let result = await libLink.messages.listRoles.send(getControl());
let newRole = result.list.find(role => role.name === "new");
assert.deepEqual(newRole.permissions, ["core.slave.list", "core.instance.list"]);
assert.deepEqual(newRole.permissions, ["core.host.list", "core.instance.list"]);
});
it("should remove permissions with --remove-perms", async function() {
let args = "--name new --remove-perms core.slave.list";
let args = "--name new --remove-perms core.host.list";
await execCtl(`role edit new ${args}`);
let result = await libLink.messages.listRoles.send(getControl());
let newRole = result.list.find(role => role.name === "new");
+19 -19
View File
@@ -26,7 +26,7 @@ class TestControl extends libLink.Link {
constructor(connector) {
super("control", "controller", connector);
libLink.attachAllMessages(this);
this.slaveUpdates = [];
this.hostUpdates = [];
this.instanceUpdates = [];
this.saveListUpdates = [];
this.modUpdates = [];
@@ -34,9 +34,9 @@ class TestControl extends libLink.Link {
this.userUpdates = [];
this.connector.on("connect", () => {
libLink.messages.setSlaveSubscriptions.send(
this, { all: true, slave_ids: [] }
).catch(err => logger.error(`Error setting slave subscriptions:\n${err.stack}`));
libLink.messages.setHostSubscriptions.send(
this, { all: true, host_ids: [] }
).catch(err => logger.error(`Error setting host subscriptions:\n${err.stack}`));
libLink.messages.setInstanceSubscriptions.send(
this, { all: true, instance_ids: [] }
).catch(err => logger.error(`Error setting instance subscriptions:\n${err.stack}`));
@@ -61,8 +61,8 @@ class TestControl extends libLink.Link {
async accountUpdateEventHandler() { }
async slaveUpdateEventHandler(message) {
this.slaveUpdates.push(message.data);
async hostUpdateEventHandler(message) {
this.hostUpdates.push(message.data);
}
async instanceUpdateEventHandler(message) {
@@ -118,7 +118,7 @@ async function get(urlPath) {
}
let controllerProcess;
let slaveProcess;
let hostProcess;
let control;
let url = "https://localhost:4443/";
@@ -127,7 +127,7 @@ let instancesDir = path.join("temp", "test", "instances");
let databaseDir = path.join("temp", "test", "database");
let pluginListPath = path.join("temp", "test", "plugin-list.json");
let controllerConfigPath = path.join("temp", "test", "config-controller.json");
let slaveConfigPath = path.join("temp", "test", "config-slave.json");
let hostConfigPath = path.join("temp", "test", "config-host.json");
let controlConfigPath = path.join("temp", "test", "config-control.json");
async function exec(command, options = {}) {
@@ -185,7 +185,7 @@ before(async function() {
await fs.remove(pluginListPath);
await fs.remove(controllerConfigPath);
await fs.remove(slaveConfigPath);
await fs.remove(hostConfigPath);
await fs.remove(controlConfigPath);
await fs.ensureDir(path.join("temp", "test"));
@@ -210,11 +210,11 @@ before(async function() {
controllerProcess = await spawn("controller:", "node ../../packages/controller run", /Started controller/);
await execCtl("slave create-config --id 4 --name slave --generate-token");
await exec(`node ../../packages/slave config set slave.factorio_directory ${path.join("..", "..", "factorio")}`);
await exec("node ../../packages/slave config set slave.tls_ca ../../test/file/tls/cert.pem");
await execCtl("host create-config --id 4 --name host --generate-token");
await exec(`node ../../packages/host config set host.factorio_directory ${path.join("..", "..", "factorio")}`);
await exec("node ../../packages/host config set host.tls_ca ../../test/file/tls/cert.pem");
slaveProcess = await spawn("slave:", "node ../../packages/slave run", /Started slave/);
hostProcess = await spawn("host:", "node ../../packages/host run", /Started host/);
let tlsCa = await fs.readFile("test/file/tls/cert.pem");
let controlConnector = new TestControlConnector(url, 2, tlsCa);
@@ -236,10 +236,10 @@ before(async function() {
after(async function() {
this.timeout(20000);
if (slaveProcess) {
console.log("Shutting down slave");
slaveProcess.kill("SIGINT");
await events.once(slaveProcess, "exit");
if (hostProcess) {
console.log("Shutting down host");
hostProcess.kill("SIGINT");
await events.once(hostProcess, "exit");
}
if (controllerProcess) {
console.log("Shutting down controller");
@@ -253,7 +253,7 @@ after(async function() {
// Ensure the test processes are stopped.
process.on("exit", () => {
if (slaveProcess) { slaveProcess.kill(); }
if (hostProcess) { hostProcess.kill(); }
if (controllerProcess) { controllerProcess.kill(); }
});
@@ -274,6 +274,6 @@ module.exports = {
instancesDir,
databaseDir,
controllerConfigPath,
slaveConfigPath,
hostConfigPath,
controlConfigPath,
};
+12 -12
View File
@@ -11,12 +11,12 @@ describe("lib/command", function() {
let testRole = { id: 28, name: "Test Role", description: "Test", permissions: [] };
let mockConnector = new mock.MockConnector();
mockConnector.on("send", function(message) {
if (message.type === "list_slaves_request") {
if (message.type === "list_hosts_request") {
this.emit("message", {
seq: 1, type: "list_slaves_response",
seq: 1, type: "list_hosts_response",
data: {
seq: message.seq,
list: [{ agent: "test", version: "0.1", id: 11, name: "Test Slave", connected: false }],
list: [{ agent: "test", version: "0.1", id: 11, name: "Test Host", connected: false }],
},
});
} else if (message.type === "list_instances_request") {
@@ -24,7 +24,7 @@ describe("lib/command", function() {
seq: 1, type: "list_instances_response",
data: {
seq: message.seq,
list: [{ id: 57, assigned_slave: 4, name: "Test Instance", status: "stopped" }],
list: [{ id: 57, assigned_host: 4, name: "Test Instance", status: "stopped" }],
},
});
} else if (message.type === "list_roles_request") {
@@ -39,21 +39,21 @@ describe("lib/command", function() {
});
let testControl = new mock.MockControl(mockConnector);
libLink.messages.listSlaves.attach(testControl);
libLink.messages.listHosts.attach(testControl);
libLink.messages.listInstances.attach(testControl);
libLink.messages.listRoles.attach(testControl);
describe("resolveSlave", function() {
describe("resolveHost", function() {
it("should pass an integer like string back", async function() {
assert.equal(await libCommand.resolveSlave(null, "123"), 123);
assert.equal(await libCommand.resolveHost(null, "123"), 123);
});
it("should resolve a slave name with the controller", async function() {
assert.equal(await libCommand.resolveSlave(testControl, "Test Slave"), 11);
it("should resolve a host name with the controller", async function() {
assert.equal(await libCommand.resolveHost(testControl, "Test Host"), 11);
});
it("should throw if slave is not found", async function() {
it("should throw if host is not found", async function() {
await assert.rejects(
libCommand.resolveSlave(testControl, "invalid"),
new libErrors.CommandError("No slave named invalid")
libCommand.resolveHost(testControl, "invalid"),
new libErrors.CommandError("No host named invalid")
);
});
});
+4 -4
View File
@@ -111,13 +111,13 @@ describe("lib/logging_utils.js", function() {
it("should filter by controller", async function() {
let log = await libLoggingUtils.queryLog(logDir, { controller: true }, index());
assert.deepEqual(log, allLines.filter(
info => info.slave_id === undefined && info.instance_id === undefined
info => info.host_id === undefined && info.instance_id === undefined
));
});
it("should filter by slave_ids", async function() {
let log = await libLoggingUtils.queryLog(logDir, { slave_ids: [1, 2] }, index());
it("should filter by host_ids", async function() {
let log = await libLoggingUtils.queryLog(logDir, { host_ids: [1, 2] }, index());
assert.deepEqual(log, allLines.filter(
info => [1, 2].includes(info.slave_id) && info.instance_id === undefined
info => [1, 2].includes(info.host_id) && info.instance_id === undefined
));
});
it("should filter by instance_ids", async function() {
+2 -2
View File
@@ -66,8 +66,8 @@ describe("lib/plugin", function() {
await controllerPlugin.onInstanceConfigFieldChanged({}, {}, "foo", null);
await controllerPlugin.onMetrics();
await controllerPlugin.onShutdown();
controllerPlugin.onSlaveConnectionEvent({}, "connect");
await controllerPlugin.onPrepareSlaveDisconnect({});
controllerPlugin.onHostConnectionEvent({}, "connect");
await controllerPlugin.onPrepareHostDisconnect({});
});
});
+7 -7
View File
@@ -125,7 +125,7 @@ class MockServer extends events.EventEmitter {
class MockInstance extends libLink.Link {
constructor() {
super("instance", "slave", new MockConnector());
super("instance", "host", new MockConnector());
this.logger = new MockLogger();
this.server = new MockServer();
this.name = "test";
@@ -150,9 +150,9 @@ class MockInstance extends libLink.Link {
}
}
class MockSlave extends libLink.Link {
class MockHost extends libLink.Link {
constructor() {
super("slave", "controller", new MockConnector());
super("host", "controller", new MockConnector());
}
}
@@ -193,7 +193,7 @@ class MockController {
["player", new libUsers.User({ name: "player", roles: [1] }, this.userManager.roles)],
]);
this.instances = new Map();
this.slaves = new Map();
this.hosts = new Map();
}
getControllerUrl() {
@@ -228,8 +228,8 @@ async function createControllerPlugin(ControllerPluginClass, info) {
async function createInstancePlugin(InstancePluginClass, info) {
let instance = new MockInstance();
let slave = new MockSlave();
let plugin = new InstancePluginClass(info, instance, slave);
let host = new MockHost();
let plugin = new InstancePluginClass(info, instance, host);
libPlugin.attachPluginMessages(instance, plugin);
await plugin.init();
return plugin;
@@ -242,7 +242,7 @@ module.exports = {
MockConnector,
MockServer,
MockInstance,
MockSlave,
MockHost,
MockControl,
MockController,