From bdf299329765f1e39989e924168a90865dbc4d75 Mon Sep 17 00:00:00 2001 From: NeoPlays <80448387+NeoPlays@users.noreply.github.com> Date: Thu, 10 Jul 2025 13:03:17 +0200 Subject: [PATCH 1/2] ADD: dev lane for updates.json --- controls/roles/update-services/tasks/main.yml | 7 +++++-- controls/roles/update-stereum/tasks/main.yml | 6 +++++- launcher/src/backend/NodeConnection.js | 1 + launcher/src/backend/NodeUpdates.js | 6 +++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/controls/roles/update-services/tasks/main.yml b/controls/roles/update-services/tasks/main.yml index 2bf67a7c6f..0f0f2a6f30 100644 --- a/controls/roles/update-services/tasks/main.yml +++ b/controls/roles/update-services/tasks/main.yml @@ -1,7 +1,11 @@ --- +- name: Set lane suffix + set_fact: + updates_lane_suffix: "{{ '.dev' if (stereum.settings.updates.lane | default('stable')) == 'dev' else '' }}" + - name: Download update metadata uri: - url: https://stereum.net/downloads/updates.json + url: "https://stereum.net/downloads/updates{{ updates_lane_suffix }}.json" method: GET return_content: yes status_code: 200 @@ -26,5 +30,4 @@ - name: Update services include_tasks: update-service.yml with_items: "{{ services_to_update }}" - # EOF diff --git a/controls/roles/update-stereum/tasks/main.yml b/controls/roles/update-stereum/tasks/main.yml index 7cba86b196..92f24ec26a 100644 --- a/controls/roles/update-stereum/tasks/main.yml +++ b/controls/roles/update-stereum/tasks/main.yml @@ -5,9 +5,13 @@ state: absent become: yes +- name: Set lane suffix + set_fact: + updates_lane_suffix: "{{ '.dev' if (stereum.settings.updates.lane | default('stable')) == 'dev' else '' }}" + - name: Download update metadata uri: - url: https://stereum.net/downloads/updates.json + url: "https://stereum.net/downloads/updates{{ updates_lane_suffix }}.json" method: GET return_content: true status_code: 200 diff --git a/launcher/src/backend/NodeConnection.js b/launcher/src/backend/NodeConnection.js index 904aa69123..351e285cab 100755 --- a/launcher/src/backend/NodeConnection.js +++ b/launcher/src/backend/NodeConnection.js @@ -29,6 +29,7 @@ export class NodeConnection { this.nodeConnectionParams = nodeConnectionParams; this.os = null; this.osv = null; + this.settings = null; this.nodeUpdates = new NodeUpdates(this); this.configManager = new ConfigManager(this); } diff --git a/launcher/src/backend/NodeUpdates.js b/launcher/src/backend/NodeUpdates.js index 7ba98037fe..b49da8d727 100644 --- a/launcher/src/backend/NodeUpdates.js +++ b/launcher/src/backend/NodeUpdates.js @@ -37,7 +37,11 @@ export class NodeUpdates { * @returns {Object} - updates available for services */ async checkUpdates() { - let response = await axios.get("https://stereum.net/downloads/updates.json"); + if (!this.nodeConnection?.settings?.lane) { + await this.nodeConnection.findStereumSettings(); + } + const lane = this.nodeConnection?.settings?.lane || "stable"; + let response = await axios.get(`https://stereum.net/downloads/updates${lane == "dev" ? ".dev" : ""}.json`); if (global.branch === "main") response.data.stereum.push({ name: "HEAD", commit: "main" }); return response.data; } From 90fabe8c75f541f7961de192f452c3adb8baaf0e Mon Sep 17 00:00:00 2001 From: NeoPlays <80448387+NeoPlays@users.noreply.github.com> Date: Thu, 10 Jul 2025 14:32:26 +0200 Subject: [PATCH 2/2] FIX: Tests --- launcher/src/backend/NodeUpdates.js | 4 +- .../backend/tests/unit/NodeConnection.test.js | 44 ++++++++++++------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/launcher/src/backend/NodeUpdates.js b/launcher/src/backend/NodeUpdates.js index b49da8d727..1a825661a1 100644 --- a/launcher/src/backend/NodeUpdates.js +++ b/launcher/src/backend/NodeUpdates.js @@ -37,10 +37,10 @@ export class NodeUpdates { * @returns {Object} - updates available for services */ async checkUpdates() { - if (!this.nodeConnection?.settings?.lane) { + if (!this.nodeConnection.settings?.stereum?.settings?.updates?.lane) { await this.nodeConnection.findStereumSettings(); } - const lane = this.nodeConnection?.settings?.lane || "stable"; + const lane = this.nodeConnection.settings?.stereum?.settings?.updates?.lane || "stable"; let response = await axios.get(`https://stereum.net/downloads/updates${lane == "dev" ? ".dev" : ""}.json`); if (global.branch === "main") response.data.stereum.push({ name: "HEAD", commit: "main" }); return response.data; diff --git a/launcher/src/backend/tests/unit/NodeConnection.test.js b/launcher/src/backend/tests/unit/NodeConnection.test.js index 7e1e476ae5..89e6eb93ec 100755 --- a/launcher/src/backend/tests/unit/NodeConnection.test.js +++ b/launcher/src/backend/tests/unit/NodeConnection.test.js @@ -110,7 +110,7 @@ test("findStereumSettings failure", async () => { await nodeConnection.findStereumSettings(); - expect(nodeConnection.settings).toBeUndefined(); + expect(nodeConnection.settings).toBeNull(); }); test("prepareStereumNode failure ubuntu installpkg", async () => { @@ -188,6 +188,7 @@ test("prepareStereumNode failure ubuntu install", async () => { mMock .mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS .mockReturnValueOnce({ rc: 0 }) // install pkg + .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings .mockReturnValueOnce({ rc: 1, stderr: "" }); // install SSHService.SSHService.mockImplementation(() => { return { @@ -203,7 +204,7 @@ test("prepareStereumNode failure ubuntu install", async () => { expect(e).toEqual(new Error("Can't install ansible role: ")); }); - expect(mMock.mock.calls.length).toBe(4); + expect(mMock.mock.calls.length).toBe(5); }); test("prepareStereumNode error ubuntu install", async () => { @@ -214,6 +215,7 @@ test("prepareStereumNode error ubuntu install", async () => { .mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS .mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist .mockReturnValueOnce({ rc: 0 }) // install pkg + .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings .mockRejectedValue("connection lost"); // install SSHService.SSHService.mockImplementation(() => { return { @@ -229,7 +231,7 @@ test("prepareStereumNode error ubuntu install", async () => { expect(e).toEqual(new Error("Can't install ansible roles: connection lost")); }); - expect(mMock.mock.calls.length).toBe(4); + expect(mMock.mock.calls.length).toBe(5); }); test("prepareStereumNode success", async () => { @@ -239,8 +241,9 @@ test("prepareStereumNode success", async () => { mMock .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings .mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS - .mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist .mockReturnValueOnce({ rc: 0 }) // install pkg + .mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist + .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings .mockReturnValueOnce({ rc: 0 }) // install .mockReturnValueOnce({ rc: 0 }) // playbook ansible .mockReturnValueOnce({ rc: 0 }); // playbook ansible @@ -267,7 +270,7 @@ test("prepareStereumNode success", async () => { playbookRunRef: expect.any(String), }); - expect(mMock.mock.calls.length).toBe(7); + expect(mMock.mock.calls.length).toBe(8); expect(mMock.mock.calls[0][0]).toMatch(/cat/); expect(mMock.mock.calls[0][0]).toMatch(/stereum.yaml/); @@ -277,10 +280,13 @@ test("prepareStereumNode success", async () => { expect(mMock.mock.calls[2][0]).toMatch(/apt install/); - expect(mMock.mock.calls[4][0]).toMatch(/git checkout/); + expect(mMock.mock.calls[4][0]).toMatch(/cat/); + expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/); + + expect(mMock.mock.calls[5][0]).toMatch(/git checkout/); - expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/); - expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/); + expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/); + expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/); }); test("prepareStereumNode error playbook", async () => { @@ -292,6 +298,7 @@ test("prepareStereumNode error playbook", async () => { .mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS .mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist .mockReturnValueOnce({ rc: 0 }) // install pkg + .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings .mockReturnValueOnce({ rc: 0 }) // install .mockRejectedValue("connection interrupted"); // playbook ansible SSHService.SSHService.mockImplementation(() => { @@ -309,16 +316,19 @@ test("prepareStereumNode error playbook", async () => { expect(e).toEqual(new Error("Can't run setup playbook: Error: Can't run playbook: connection interrupted")); }); - expect(mMock.mock.calls.length).toBe(6); + expect(mMock.mock.calls.length).toBe(7); expect(mMock.mock.calls[1][0]).toMatch(/cat/); expect(mMock.mock.calls[1][0]).toMatch(/release/); expect(mMock.mock.calls[2][0]).toMatch(/apt install/); - expect(mMock.mock.calls[4][0]).toMatch(/git checkout/); + expect(mMock.mock.calls[4][0]).toMatch(/cat/); + expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/); + + expect(mMock.mock.calls[5][0]).toMatch(/git checkout/); - expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/); + expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/); }); test("prepareStereumNode failure playbook", async () => { @@ -326,10 +336,11 @@ test("prepareStereumNode failure playbook", async () => { const SSHService = require("../../SSHService"); const mMock = jest.fn(); mMock - .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings + .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests\n lane: stable" }) // find settings .mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS .mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist .mockReturnValueOnce({ rc: 0 }) // install pkg + .mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests\n lane: stable" }) // find settings .mockReturnValueOnce({ rc: 0 }) // install .mockReturnValueOnce({ rc: 1, stderr: "asdf" }); // playbook ansible SSHService.SSHService.mockImplementation(() => { @@ -347,15 +358,18 @@ test("prepareStereumNode failure playbook", async () => { expect(e).toEqual(new Error("Can't run setup playbook: Error: Failed running 'setup': asdf")); }); - expect(mMock.mock.calls.length).toBe(6); + expect(mMock.mock.calls.length).toBe(7); expect(mMock.mock.calls[1][0]).toMatch(/cat/); expect(mMock.mock.calls[1][0]).toMatch(/release/); expect(mMock.mock.calls[2][0]).toMatch(/apt install/); - expect(mMock.mock.calls[4][0]).toMatch(/git checkout/); + expect(mMock.mock.calls[4][0]).toMatch(/cat/); + expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/); + + expect(mMock.mock.calls[5][0]).toMatch(/git checkout/); - expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/); + expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/); }); test("playbookStatus error", async () => {