Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions controls/roles/update-services/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -26,5 +30,4 @@
- name: Update services
include_tasks: update-service.yml
with_items: "{{ services_to_update }}"

# EOF
6 changes: 5 additions & 1 deletion controls/roles/update-stereum/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions launcher/src/backend/NodeConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 5 additions & 1 deletion launcher/src/backend/NodeUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?.stereum?.settings?.updates?.lane) {
await this.nodeConnection.findStereumSettings();
}
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;
}
Expand Down
44 changes: 29 additions & 15 deletions launcher/src/backend/tests/unit/NodeConnection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 {
Expand All @@ -203,7 +204,7 @@ test("prepareStereumNode failure ubuntu install", async () => {
expect(e).toEqual(new Error("Can't install ansible role: <stderr empty>"));
});

expect(mMock.mock.calls.length).toBe(4);
expect(mMock.mock.calls.length).toBe(5);
});

test("prepareStereumNode error ubuntu install", async () => {
Expand All @@ -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 {
Expand All @@ -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 () => {
Expand All @@ -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
Expand All @@ -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/);
Expand All @@ -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 () => {
Expand All @@ -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(() => {
Expand All @@ -309,27 +316,31 @@ 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 () => {
jest.mock("../../SSHService");
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(() => {
Expand All @@ -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 () => {
Expand Down