Skip to content

Commit 3d8a1db

Browse files
committed
Merge branch 'development' of github.com:threefoldtech/tfgrid-sdk-ts into development_fix_gateway_query
2 parents 86e9b3a + 1ecaaf3 commit 3d8a1db

File tree

8 files changed

+317
-69
lines changed

8 files changed

+317
-69
lines changed

packages/grid_client/docs/network/mycelium_network.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This configuration is set on [workload data](../../src/zos/zmachine.ts) and [net
1616

1717
In case user needs to support mycelium:
1818

19-
- flag `mycelium` field in workload with true, also the `planetary` field should be flagged with true.
19+
- flag `mycelium` field in workload with true.
2020
- User can support hex seed which ip will be generated from or they'll be generated automatically.
2121
- providing seeds, that's what makes ip fixed from anywhere.
2222
> Note user can't use same network seed in multiple nodes.

packages/grid_client/src/primitives/nodes.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,10 @@ class Nodes {
372372
async filterNodes(options: FilterOptions = {}, url = ""): Promise<NodeInfo[]> {
373373
let nodes: NodeInfo[] = [];
374374
url = url || this.proxyURL;
375+
/*
376+
this is tmp solution to exclude node 11 on dev net only and should be removed when the issue is fixed; tracked in https://github.com/threefoldtech/tfgrid-sdk-ts/issues/3855
377+
*/
378+
if (url.includes("dev")) options.nodeExclude = options.nodeExclude ? [...options.nodeExclude, 11] : [11];
375379
options.features = this.getFeaturesFromFilters(options);
376380
const query = this.getNodeUrlQuery(options);
377381
nodes = await send("get", urlJoin(url, `/nodes?${query}`), "", {});

packages/grid_client/src/zos/znet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ class Znet extends WorkloadData {
5555
}
5656
}
5757

58-
export { Znet, Peer };
58+
export { Znet, Peer, Mycelium };

packages/grid_client/tests/modules/vm.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ test("TC1228 - VM: Deploy a VM", async () => {
6969
farmId: 1,
7070
availableFor: await gridClient.twins.get_my_twin_id(),
7171
features: [Features.wireguard],
72+
nodeExclude: [11],
7273
} as FilterOptions);
7374
} catch (error) {
7475
//Log the resources that were not found.
@@ -88,6 +89,7 @@ test("TC1228 - VM: Deploy a VM", async () => {
8889
farmId: 1,
8990
availableFor: await gridClient.twins.get_my_twin_id(),
9091
features: [Features.wireguard],
92+
nodeExclude: [11],
9193
} as FilterOptions);
9294
}
9395
const nodeId = await getOnlineNode(nodes);
@@ -234,6 +236,7 @@ test("TC2847 - VM: Deploy a VM With Mycelium", async () => {
234236
farmId: 1,
235237
availableFor: await gridClient.twins.get_my_twin_id(),
236238
features: [Features.wireguard],
239+
nodeExclude: [11],
237240
} as FilterOptions);
238241
} catch (error) {
239242
//Log the resources that were not found.
@@ -253,6 +256,7 @@ test("TC2847 - VM: Deploy a VM With Mycelium", async () => {
253256
farmId: 1,
254257
availableFor: await gridClient.twins.get_my_twin_id(),
255258
features: [Features.wireguard],
259+
nodeExclude: [11],
256260
} as FilterOptions);
257261
}
258262
const nodeId = await getOnlineNode(nodes);
@@ -403,6 +407,7 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => {
403407
farmId: 1,
404408
availableFor: await gridClient.twins.get_my_twin_id(),
405409
features: [Features.wireguard],
410+
nodeExclude: [11],
406411
} as FilterOptions);
407412
} catch (error) {
408413
//Log the resources that were not found.
@@ -423,6 +428,7 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => {
423428
farmId: 1,
424429
availableFor: await gridClient.twins.get_my_twin_id(),
425430
features: [Features.wireguard],
431+
nodeExclude: [11],
426432
} as FilterOptions);
427433
}
428434
const nodeId = await getOnlineNode(nodes);
@@ -499,9 +505,9 @@ test("TC1229 - VM: Deploy a VM With a Disk", async () => {
499505
//Verify that the disk was added successfully.
500506
await ssh.execCommand("df -h").then(async function (result) {
501507
const splittedRes = result.stdout.split("\n");
502-
log(splittedRes[4]);
503-
expect(splittedRes[4]).toContain(mountPoint);
504-
expect(splittedRes[4]).toContain(diskSize.toString());
508+
log(splittedRes[5]);
509+
expect(splittedRes[5]).toContain(mountPoint);
510+
expect(splittedRes[5]).toContain(diskSize.toString());
505511
});
506512
} finally {
507513
//Disconnect from the machine
@@ -727,7 +733,11 @@ test("TC1230 - VM: Deploy Multiple VMs on Different Nodes", async () => {
727733
log(result.stdout);
728734
expect(result.stdout).toContain(vmEnvVarValue[maxIterations]);
729735
});
730-
736+
await ssh.execCommand("apk add util-linux").then(function (result) {
737+
if (result.stderr) {
738+
throw new Error("Failed to install util-linux");
739+
}
740+
});
731741
//Verify VM Resources(CPU)
732742
await ssh.execCommand("lscpu").then(async function (result) {
733743
const splittedRes = result.stdout.split("\n");
Lines changed: 279 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,279 @@
1+
import { plainToClass } from "class-transformer";
2+
3+
import {
4+
DeploymentResult,
5+
Encryption,
6+
MachineInterface,
7+
Mycelium,
8+
MyceliumIP,
9+
NetworkLight,
10+
Peer,
11+
QuantumCompression,
12+
QuantumSafeConfig,
13+
QuantumSafeFSConfig,
14+
QuantumSafeMeta,
15+
ResultStates,
16+
Workload,
17+
WorkloadTypes,
18+
ZdbBackend,
19+
ZdbGroup,
20+
ZdbModes,
21+
ZmachineLight,
22+
ZmachineLightNetwork,
23+
} from "../../src";
24+
import {
25+
ComputeCapacity,
26+
GatewayFQDNProxy,
27+
GatewayNameProxy,
28+
Mount,
29+
PublicIP,
30+
QuantumSafeFS,
31+
Volume,
32+
Zdb,
33+
Zlogs,
34+
Zmachine,
35+
ZmachineNetwork,
36+
Zmount,
37+
Znet,
38+
} from "../../src";
39+
import { PublicIPv4 } from "../../src/zos/ipv4";
40+
41+
let workload: Workload;
42+
43+
const createDataInstance = (type: WorkloadTypes) => {
44+
let instance;
45+
const network = new ZmachineNetwork();
46+
const networklight = new ZmachineLightNetwork();
47+
const interfaces = new MachineInterface();
48+
const myceliumip = new MyceliumIP();
49+
50+
const computeCapacity = new ComputeCapacity();
51+
computeCapacity.cpu = 1;
52+
computeCapacity.memory = 256 * 1024 ** 2;
53+
const disks = new Mount();
54+
disks.name = "zdisk";
55+
disks.mountpoint = "/mnt/data";
56+
const peer = new Peer();
57+
peer.subnet = "10.0.1.0/24";
58+
peer.wireguard_public_key = "9I8H7G6F5E4D3C2B1A0J";
59+
peer.allowed_ips = ["10.0.1.6"];
60+
peer.endpoint = "185.206.122.31:5566";
61+
const mycelium = new Mycelium();
62+
mycelium.hex_key = "abc123";
63+
64+
const rootfs_size = 2;
65+
const size = 100 * 1024 ** 2;
66+
const qsfsConfig = new QuantumSafeFSConfig();
67+
const encryption = new Encryption();
68+
const meta = new QuantumSafeMeta();
69+
const config = new QuantumSafeConfig();
70+
const backends = new ZdbBackend();
71+
const groups = new ZdbGroup();
72+
const compression = new QuantumCompression();
73+
const qsfsCache = 262144000;
74+
75+
switch (type) {
76+
case WorkloadTypes.zmachine:
77+
instance = new Zmachine();
78+
network.planetary = true;
79+
network.public_ip = "10.249.0.0/16";
80+
network.interfaces = [
81+
{
82+
network: "znetwork",
83+
ip: "10.20.2.2",
84+
},
85+
];
86+
network.mycelium = {
87+
network: "mycelium_net",
88+
hex_seed: "abc123",
89+
};
90+
91+
instance.flist = "https://hub.grid.tf/tf-official-vms/ubuntu-22.04.flist";
92+
instance.network = network;
93+
instance.size = rootfs_size * 1024 ** 3;
94+
instance.mounts = [disks];
95+
instance.entrypoint = "/sbin/zinit init";
96+
instance.compute_capacity = computeCapacity;
97+
instance.env = { key: "value" };
98+
instance.corex = false;
99+
instance.gpu = ["AMD", "NIVIDIA"];
100+
break;
101+
case WorkloadTypes.zmachinelight:
102+
instance = new ZmachineLight();
103+
instance.flist = "https://hub.grid.tf/tf-official-vms/ubuntu-22.04.flist";
104+
interfaces.network = "znetwork";
105+
interfaces.ip = "10.20.2.2";
106+
networklight.interfaces = [interfaces];
107+
myceliumip.network = "mycelium_net";
108+
myceliumip.hex_seed = "abc123";
109+
networklight.mycelium = myceliumip;
110+
instance.network = networklight;
111+
instance.size = rootfs_size * 1024 ** 3;
112+
instance.compute_capacity = computeCapacity;
113+
instance.mounts = [disks];
114+
instance.env = { key: "value" };
115+
instance.entrypoint = "/sbin/zinit init";
116+
instance.corex = false;
117+
instance.gpu = ["AMD", "NIVIDIA"];
118+
break;
119+
case WorkloadTypes.zmount:
120+
instance = new Zmount();
121+
instance.size = size;
122+
break;
123+
124+
case WorkloadTypes.volume:
125+
instance = new Volume();
126+
instance.size = size;
127+
break;
128+
129+
case WorkloadTypes.network:
130+
instance = new Znet();
131+
instance.subnet = "10.0.0.1/32";
132+
instance.ip_range = "10.0.0.2/32";
133+
instance.wireguard_private_key = "2BwI0a7lVYxeKsh7jklashakdfjasdf7jksdHf";
134+
instance.wireguard_listen_port = 5566;
135+
instance.peers = [peer];
136+
instance.mycelium = mycelium;
137+
break;
138+
case WorkloadTypes.networklight:
139+
instance = new NetworkLight();
140+
instance.subnet = "10.0.0.1/32";
141+
instance.mycelium = mycelium;
142+
break;
143+
case WorkloadTypes.zdb:
144+
instance = new Zdb();
145+
instance.size = size;
146+
instance.mode = ZdbModes.user;
147+
instance.password = "123456";
148+
instance.public = false;
149+
break;
150+
151+
case WorkloadTypes.ip:
152+
instance = new PublicIP();
153+
instance.v4 = true;
154+
instance.v6 = false;
155+
break;
156+
157+
case WorkloadTypes.ipv4:
158+
instance = new PublicIPv4();
159+
break;
160+
161+
case WorkloadTypes.qsfs:
162+
instance = new QuantumSafeFS();
163+
164+
qsfsConfig.minimal_shards = 2;
165+
qsfsConfig.expected_shards = 3;
166+
qsfsConfig.redundant_groups = 0;
167+
qsfsConfig.redundant_nodes = 0;
168+
qsfsConfig.max_zdb_data_dir_size = 2;
169+
encryption.algorithm = "algorithm";
170+
encryption.key = "EncryptionKey12345678";
171+
qsfsConfig.encryption = encryption;
172+
meta.type = "qsfs";
173+
config.prefix = "qsfs";
174+
config.encryption = encryption;
175+
backends.address = "localhost";
176+
backends.namespace = "http://localhost";
177+
backends.password = "password";
178+
groups.backends = [backends];
179+
qsfsConfig.groups = [groups];
180+
config.backends = [backends];
181+
meta.config = config;
182+
qsfsConfig.meta = meta;
183+
compression.algorithm = "algorithm";
184+
qsfsConfig.compression = compression;
185+
186+
instance.cache = qsfsCache;
187+
instance.config = qsfsConfig;
188+
break;
189+
190+
case WorkloadTypes.zlogs:
191+
instance = new Zlogs();
192+
instance.zmachine = "zmachine";
193+
instance.output = "zlog";
194+
break;
195+
196+
case WorkloadTypes.gatewayfqdnproxy:
197+
instance = new GatewayFQDNProxy();
198+
instance.fqdn = "dmftv9qfff.gent02.dev.grid.tf";
199+
instance.tls_passthrough = false;
200+
instance.backends = ["http://185.206.122.43:80"];
201+
break;
202+
203+
case WorkloadTypes.gatewaynameproxy:
204+
instance = new GatewayNameProxy();
205+
instance.name = "GatewayNameProxy";
206+
instance.tls_passthrough = false;
207+
instance.backends = ["http://185.206.122.43:80"];
208+
break;
209+
210+
default:
211+
throw new Error(`Invalid WorkloadType: ${type}`);
212+
}
213+
214+
return instance;
215+
};
216+
217+
describe.each(Object.values(WorkloadTypes))("Workload Tests for %s", type => {
218+
beforeEach(() => {
219+
const dataInstance = createDataInstance(type);
220+
workload = new Workload();
221+
workload.version = 1;
222+
workload.name = "Test Workload";
223+
workload.type = type;
224+
workload.metadata = "Metadata";
225+
workload.description = "A test for workload";
226+
workload.data = dataInstance;
227+
workload.result = new DeploymentResult();
228+
workload.result.created = Date.now();
229+
workload.result.state = ResultStates.ok;
230+
workload.result.message = "Deployment successful";
231+
workload.result.data = workload.data;
232+
});
233+
234+
test("should create a valid Workload instance", () => {
235+
expect(workload).toBeInstanceOf(Workload);
236+
});
237+
238+
test("should handle valid Workload properties", () => {
239+
expect(workload.version).toBe(1);
240+
expect(workload.name).toBe("Test Workload");
241+
expect(workload.type).toBe(type);
242+
expect(workload.metadata).toBe("Metadata");
243+
expect(workload.description).toBe("A test for workload");
244+
expect(workload.result.created).toBeGreaterThan(0);
245+
expect(workload.result.state).toBe(ResultStates.ok);
246+
expect(workload.result.message).toBe("Deployment successful");
247+
});
248+
249+
test("should correctly serialize and deserialize Workload", () => {
250+
const serialized = JSON.stringify(workload);
251+
const deserialized = plainToClass(Workload, JSON.parse(serialized));
252+
expect(deserialized).toBeInstanceOf(Workload);
253+
expect(deserialized).toEqual(workload);
254+
});
255+
256+
test("should correctly compute the challenge string", () => {
257+
const expectedChallenge =
258+
workload.version.toString() +
259+
workload.name +
260+
workload.type.toString() +
261+
workload.metadata +
262+
workload.description +
263+
workload.data.challenge();
264+
265+
expect(workload.challenge()).toBe(expectedChallenge);
266+
});
267+
268+
test("should handle invalid DeploymentResult", () => {
269+
const invalidResult = new DeploymentResult();
270+
invalidResult.created = Date.now();
271+
invalidResult.state = "invalid-state" as any;
272+
invalidResult.message = "Deployment successful";
273+
invalidResult.data = workload.data;
274+
275+
workload.result = invalidResult;
276+
277+
expect(() => workload.challenge()).not.toThrow();
278+
});
279+
});
-25.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)