Skip to content

Commit 0ef18aa

Browse files
authored
ADD: dev lane for updates.json (#2272)
* ADD: dev lane for updates.json * FIX: Tests
1 parent 11ba1b5 commit 0ef18aa

5 files changed

Lines changed: 45 additions & 19 deletions

File tree

controls/roles/update-services/tasks/main.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
---
2+
- name: Set lane suffix
3+
set_fact:
4+
updates_lane_suffix: "{{ '.dev' if (stereum.settings.updates.lane | default('stable')) == 'dev' else '' }}"
5+
26
- name: Download update metadata
37
uri:
4-
url: https://stereum.net/downloads/updates.json
8+
url: "https://stereum.net/downloads/updates{{ updates_lane_suffix }}.json"
59
method: GET
610
return_content: yes
711
status_code: 200
@@ -26,5 +30,4 @@
2630
- name: Update services
2731
include_tasks: update-service.yml
2832
with_items: "{{ services_to_update }}"
29-
3033
# EOF

controls/roles/update-stereum/tasks/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
state: absent
66
become: yes
77

8+
- name: Set lane suffix
9+
set_fact:
10+
updates_lane_suffix: "{{ '.dev' if (stereum.settings.updates.lane | default('stable')) == 'dev' else '' }}"
11+
812
- name: Download update metadata
913
uri:
10-
url: https://stereum.net/downloads/updates.json
14+
url: "https://stereum.net/downloads/updates{{ updates_lane_suffix }}.json"
1115
method: GET
1216
return_content: true
1317
status_code: 200

launcher/src/backend/NodeConnection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export class NodeConnection {
2929
this.nodeConnectionParams = nodeConnectionParams;
3030
this.os = null;
3131
this.osv = null;
32+
this.settings = null;
3233
this.nodeUpdates = new NodeUpdates(this);
3334
this.configManager = new ConfigManager(this);
3435
}

launcher/src/backend/NodeUpdates.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export class NodeUpdates {
3737
* @returns {Object} - updates available for services
3838
*/
3939
async checkUpdates() {
40-
let response = await axios.get("https://stereum.net/downloads/updates.json");
40+
if (!this.nodeConnection.settings?.stereum?.settings?.updates?.lane) {
41+
await this.nodeConnection.findStereumSettings();
42+
}
43+
const lane = this.nodeConnection.settings?.stereum?.settings?.updates?.lane || "stable";
44+
let response = await axios.get(`https://stereum.net/downloads/updates${lane == "dev" ? ".dev" : ""}.json`);
4145
if (global.branch === "main") response.data.stereum.push({ name: "HEAD", commit: "main" });
4246
return response.data;
4347
}

launcher/src/backend/tests/unit/NodeConnection.test.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ test("findStereumSettings failure", async () => {
110110

111111
await nodeConnection.findStereumSettings();
112112

113-
expect(nodeConnection.settings).toBeUndefined();
113+
expect(nodeConnection.settings).toBeNull();
114114
});
115115

116116
test("prepareStereumNode failure ubuntu installpkg", async () => {
@@ -188,6 +188,7 @@ test("prepareStereumNode failure ubuntu install", async () => {
188188
mMock
189189
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
190190
.mockReturnValueOnce({ rc: 0 }) // install pkg
191+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
191192
.mockReturnValueOnce({ rc: 1, stderr: "" }); // install
192193
SSHService.SSHService.mockImplementation(() => {
193194
return {
@@ -203,7 +204,7 @@ test("prepareStereumNode failure ubuntu install", async () => {
203204
expect(e).toEqual(new Error("Can't install ansible role: <stderr empty>"));
204205
});
205206

206-
expect(mMock.mock.calls.length).toBe(4);
207+
expect(mMock.mock.calls.length).toBe(5);
207208
});
208209

209210
test("prepareStereumNode error ubuntu install", async () => {
@@ -214,6 +215,7 @@ test("prepareStereumNode error ubuntu install", async () => {
214215
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
215216
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
216217
.mockReturnValueOnce({ rc: 0 }) // install pkg
218+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
217219
.mockRejectedValue("connection lost"); // install
218220
SSHService.SSHService.mockImplementation(() => {
219221
return {
@@ -229,7 +231,7 @@ test("prepareStereumNode error ubuntu install", async () => {
229231
expect(e).toEqual(new Error("Can't install ansible roles: connection lost"));
230232
});
231233

232-
expect(mMock.mock.calls.length).toBe(4);
234+
expect(mMock.mock.calls.length).toBe(5);
233235
});
234236

235237
test("prepareStereumNode success", async () => {
@@ -239,8 +241,9 @@ test("prepareStereumNode success", async () => {
239241
mMock
240242
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
241243
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
242-
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
243244
.mockReturnValueOnce({ rc: 0 }) // install pkg
245+
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
246+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
244247
.mockReturnValueOnce({ rc: 0 }) // install
245248
.mockReturnValueOnce({ rc: 0 }) // playbook ansible
246249
.mockReturnValueOnce({ rc: 0 }); // playbook ansible
@@ -267,7 +270,7 @@ test("prepareStereumNode success", async () => {
267270
playbookRunRef: expect.any(String),
268271
});
269272

270-
expect(mMock.mock.calls.length).toBe(7);
273+
expect(mMock.mock.calls.length).toBe(8);
271274

272275
expect(mMock.mock.calls[0][0]).toMatch(/cat/);
273276
expect(mMock.mock.calls[0][0]).toMatch(/stereum.yaml/);
@@ -277,10 +280,13 @@ test("prepareStereumNode success", async () => {
277280

278281
expect(mMock.mock.calls[2][0]).toMatch(/apt install/);
279282

280-
expect(mMock.mock.calls[4][0]).toMatch(/git checkout/);
283+
expect(mMock.mock.calls[4][0]).toMatch(/cat/);
284+
expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/);
285+
286+
expect(mMock.mock.calls[5][0]).toMatch(/git checkout/);
281287

282-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
283-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
288+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
289+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
284290
});
285291

286292
test("prepareStereumNode error playbook", async () => {
@@ -292,6 +298,7 @@ test("prepareStereumNode error playbook", async () => {
292298
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
293299
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
294300
.mockReturnValueOnce({ rc: 0 }) // install pkg
301+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
295302
.mockReturnValueOnce({ rc: 0 }) // install
296303
.mockRejectedValue("connection interrupted"); // playbook ansible
297304
SSHService.SSHService.mockImplementation(() => {
@@ -309,27 +316,31 @@ test("prepareStereumNode error playbook", async () => {
309316
expect(e).toEqual(new Error("Can't run setup playbook: Error: Can't run playbook: connection interrupted"));
310317
});
311318

312-
expect(mMock.mock.calls.length).toBe(6);
319+
expect(mMock.mock.calls.length).toBe(7);
313320

314321
expect(mMock.mock.calls[1][0]).toMatch(/cat/);
315322
expect(mMock.mock.calls[1][0]).toMatch(/release/);
316323

317324
expect(mMock.mock.calls[2][0]).toMatch(/apt install/);
318325

319-
expect(mMock.mock.calls[4][0]).toMatch(/git checkout/);
326+
expect(mMock.mock.calls[4][0]).toMatch(/cat/);
327+
expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/);
328+
329+
expect(mMock.mock.calls[5][0]).toMatch(/git checkout/);
320330

321-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
331+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
322332
});
323333

324334
test("prepareStereumNode failure playbook", async () => {
325335
jest.mock("../../SSHService");
326336
const SSHService = require("../../SSHService");
327337
const mMock = jest.fn();
328338
mMock
329-
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests" }) // find settings
339+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests\n lane: stable" }) // find settings
330340
.mockReturnValueOnce({ rc: 0, stdout: "ubuntu" }) // find OS
331341
.mockReturnValueOnce({ rc: 0 }) // delete ansible roles if exist
332342
.mockReturnValueOnce({ rc: 0 }) // install pkg
343+
.mockReturnValueOnce({ rc: 0, stdout: "stereum_settings:\n settings:\n controls_install_path: /opt/tests\n lane: stable" }) // find settings
333344
.mockReturnValueOnce({ rc: 0 }) // install
334345
.mockReturnValueOnce({ rc: 1, stderr: "asdf" }); // playbook ansible
335346
SSHService.SSHService.mockImplementation(() => {
@@ -347,15 +358,18 @@ test("prepareStereumNode failure playbook", async () => {
347358
expect(e).toEqual(new Error("Can't run setup playbook: Error: Failed running 'setup': asdf"));
348359
});
349360

350-
expect(mMock.mock.calls.length).toBe(6);
361+
expect(mMock.mock.calls.length).toBe(7);
351362
expect(mMock.mock.calls[1][0]).toMatch(/cat/);
352363
expect(mMock.mock.calls[1][0]).toMatch(/release/);
353364

354365
expect(mMock.mock.calls[2][0]).toMatch(/apt install/);
355366

356-
expect(mMock.mock.calls[4][0]).toMatch(/git checkout/);
367+
expect(mMock.mock.calls[4][0]).toMatch(/cat/);
368+
expect(mMock.mock.calls[4][0]).toMatch(/stereum.yaml/);
369+
370+
expect(mMock.mock.calls[5][0]).toMatch(/git checkout/);
357371

358-
expect(mMock.mock.calls[5][0]).toMatch(/ansible-playbook/);
372+
expect(mMock.mock.calls[6][0]).toMatch(/ansible-playbook/);
359373
});
360374

361375
test("playbookStatus error", async () => {

0 commit comments

Comments
 (0)