From 1a75becc88cb7ef603e504870b7107438072c868 Mon Sep 17 00:00:00 2001 From: khaledyoussef24 Date: Sun, 25 Feb 2024 13:52:40 +0200 Subject: [PATCH] adding mycelium flag --- packages/grid_client/scripts/casperlabs.ts | 97 ++++++++++ packages/grid_client/scripts/discourse.ts | 105 +++++++++++ packages/grid_client/scripts/funkwhale.ts | 100 ++++++++++ packages/grid_client/scripts/mattermost.ts | 99 ++++++++++ packages/grid_client/scripts/nodepilot.ts | 96 ++++++++++ packages/grid_client/scripts/owncloud.ts | 99 ++++++++++ packages/grid_client/scripts/peertube.ts | 99 ++++++++++ packages/grid_client/scripts/presearch.ts | 100 ++++++++++ packages/grid_client/scripts/subsquid.ts | 98 ++++++++++ packages/grid_client/scripts/taiga.ts | 100 ++++++++++ packages/grid_client/scripts/umbrel.ts | 99 ++++++++++ packages/grid_client/scripts/wordpress.ts | 100 ++++++++++ .../tests/modules/casperlabs.test.ts | 170 +++++++++++++++++ .../tests/modules/discourse.test.ts | 177 ++++++++++++++++++ .../tests/modules/funkwhale.test.ts | 172 +++++++++++++++++ .../tests/modules/mattermost.test.ts | 172 +++++++++++++++++ .../tests/modules/nodepilot.test.ts | 170 +++++++++++++++++ .../tests/modules/owncloud.test.ts | 172 +++++++++++++++++ .../tests/modules/peertube.test.ts | 171 +++++++++++++++++ .../tests/modules/presearch.test.ts | 173 +++++++++++++++++ .../tests/modules/subsquid.test.ts | 173 +++++++++++++++++ .../grid_client/tests/modules/taiga.test.ts | 173 +++++++++++++++++ .../grid_client/tests/modules/umbrel.test.ts | 170 +++++++++++++++++ .../tests/modules/wordpress.test.ts | 173 +++++++++++++++++ 24 files changed, 3258 insertions(+) create mode 100644 packages/grid_client/scripts/casperlabs.ts create mode 100644 packages/grid_client/scripts/discourse.ts create mode 100644 packages/grid_client/scripts/funkwhale.ts create mode 100644 packages/grid_client/scripts/mattermost.ts create mode 100644 packages/grid_client/scripts/nodepilot.ts create mode 100644 packages/grid_client/scripts/owncloud.ts create mode 100644 packages/grid_client/scripts/peertube.ts create mode 100644 packages/grid_client/scripts/presearch.ts create mode 100644 packages/grid_client/scripts/subsquid.ts create mode 100644 packages/grid_client/scripts/taiga.ts create mode 100644 packages/grid_client/scripts/umbrel.ts create mode 100644 packages/grid_client/scripts/wordpress.ts create mode 100644 packages/grid_client/tests/modules/casperlabs.test.ts create mode 100644 packages/grid_client/tests/modules/discourse.test.ts create mode 100644 packages/grid_client/tests/modules/funkwhale.test.ts create mode 100644 packages/grid_client/tests/modules/mattermost.test.ts create mode 100644 packages/grid_client/tests/modules/nodepilot.test.ts create mode 100644 packages/grid_client/tests/modules/owncloud.test.ts create mode 100644 packages/grid_client/tests/modules/peertube.test.ts create mode 100644 packages/grid_client/tests/modules/presearch.test.ts create mode 100644 packages/grid_client/tests/modules/subsquid.test.ts create mode 100644 packages/grid_client/tests/modules/taiga.test.ts create mode 100644 packages/grid_client/tests/modules/umbrel.test.ts create mode 100644 packages/grid_client/tests/modules/wordpress.test.ts diff --git a/packages/grid_client/scripts/casperlabs.ts b/packages/grid_client/scripts/casperlabs.ts new file mode 100644 index 0000000000..585193d83d --- /dev/null +++ b/packages/grid_client/scripts/casperlabs.ts @@ -0,0 +1,97 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying casperlabs ================="); + log(res); + log("================= Deploying casperlabs ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access casperlabs via the browser using: http://newVMS5.${res[0].env.CASPERLABS_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/casperlabs-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + CASPERLABS_HOSTNAME: "gent01.dev.grid.tf", + }, + }, + ], + metadata: "", + description: "casperlabs machine", + }; + + //Deploy casperlabs + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + await cancel(grid3, { name: vms.name }); + + // await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/discourse.ts b/packages/grid_client/scripts/discourse.ts new file mode 100644 index 0000000000..6cfdeb1b7c --- /dev/null +++ b/packages/grid_client/scripts/discourse.ts @@ -0,0 +1,105 @@ +import { FilterOptions, generateString, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying discourse ================="); + log(res); + log("================= Deploying discourse ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access discourse via the browser using: http://captain.${res[0].env.CAPROVER_ROOT_DOMAIN}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/forum-docker-v3.1.2.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + DISCOURSE_HOSTNAME: "gent02.dev.grid.tf", + DISCOURSE_DEVELOPER_EMAILS: "test12@gmail.com", + DISCOURSE_SMTP_ADDRESS: "", + DISCOURSE_SMTP_PORT: "", + DISCOURSE_SMTP_ENABLE_START_TLS: "", + DISCOURSE_SMTP_USER_NAME: "", + DISCOURSE_SMTP_PASSWORD: "", + THREEBOT_PRIVATE_KEY: "", + FLASK_SECRET_KEY: generateString(6), + }, + }, + ], + metadata: "", + description: "discourse machine/node", + }; + + //Deploy discourse + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/funkwhale.ts b/packages/grid_client/scripts/funkwhale.ts new file mode 100644 index 0000000000..41a4341965 --- /dev/null +++ b/packages/grid_client/scripts/funkwhale.ts @@ -0,0 +1,100 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying funkwhale ================="); + log(res); + log("================= Deploying funkwhale ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access funkwhale via the browser using: http://newVMS5.${res[0].env.funkwhale_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/funkwhale-dec21.flist", + entrypoint: "/init.sh", + env: { + SSH_KEY: config.ssh_key, + DJANGO_SUPERUSER_EMAIL:"test@gmail.com", + DJANGO_SUPERUSER_USERNAME :"", + DJANGO_SUPERUSER_PASSWORD : "test123", + FUNKWHALE_HOSTNAME : "gent02.dev.grid.tf" + }, + } + ], + metadata: "", + description: "funkwhale machine/node", + }; + + //Deploy funkwhale + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/mattermost.ts b/packages/grid_client/scripts/mattermost.ts new file mode 100644 index 0000000000..2746683944 --- /dev/null +++ b/packages/grid_client/scripts/mattermost.ts @@ -0,0 +1,99 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying mattermost ================="); + log(res); + log("================= Deploying mattermost ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access mattermost via the browser using: http://captain.${res[0].env.MATTERMOST_DOMAIN}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/mattermost-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + MATTERMOST_DOMAIN: "gent02.dev.grid.tf", + SITE_URL: "https://gent02.dev.grid.tf", + DB_PASSWORD: "", + }, + }, + ], + metadata: "", + description: "mattermost machine/node", + }; + + //Deploy mattermost + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/nodepilot.ts b/packages/grid_client/scripts/nodepilot.ts new file mode 100644 index 0000000000..44bab864e0 --- /dev/null +++ b/packages/grid_client/scripts/nodepilot.ts @@ -0,0 +1,96 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying nodepilot ================="); + log(res); + log("================= Deploying nodepilot ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access nodepilot via the browser using: http://newVMS5.${res[0].env.NODEPILOT_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-vms/node-pilot-zdbfs.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + }, + }, + ], + metadata: "", + description: "nodepilot machine", + }; + + //Deploy nodepilot + // await deploy(grid3, vms); + + //Get the deployment + // await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/owncloud.ts b/packages/grid_client/scripts/owncloud.ts new file mode 100644 index 0000000000..70987b8f84 --- /dev/null +++ b/packages/grid_client/scripts/owncloud.ts @@ -0,0 +1,99 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying OwnCloud ================="); + log(res); + log("================= Deploying OwnCloud ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access OwnCloud via the browser using: http://captain.${res[0].env.CAPROVER_ROOT_DOMAIN}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/owncloud-10.9.1.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + OWNCLOUD_ADMIN_USERNAME: "test1", + OWNCLOUD_ADMIN_PASSWORD: "123456", + OWNCLOUD_DOMAIN: "gent01.dev.grid.tf", + }, + }, + ], + metadata: "", + description: "owncloud deployment machine", + }; + + // // Deploy OwnCloud + await deploy(grid3, vms); + + // // Get the deployment + await getDeployment(grid3, vms.name); + + // Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/peertube.ts b/packages/grid_client/scripts/peertube.ts new file mode 100644 index 0000000000..923065ca1d --- /dev/null +++ b/packages/grid_client/scripts/peertube.ts @@ -0,0 +1,99 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying peertube ================="); + log(res); + log("================= Deploying peertube ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access peertube via the browser using: http://newVMS5.${res[0].env.PEERTUBE_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/peertube-v3.1.1.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + PEERTUBE_ADMIN_EMAIL: "test@gmail.com", + PT_INITIAL_ROOT_PASSWORD: "test123", + PEERTUBE_WEBSERVER_HOSTNAME: "gent01.dev.grid.tf", + }, + }, + ], + metadata: "", + description: "peertube machine", + }; + + //Deploy Peertube + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/presearch.ts b/packages/grid_client/scripts/presearch.ts new file mode 100644 index 0000000000..ae490a49c4 --- /dev/null +++ b/packages/grid_client/scripts/presearch.ts @@ -0,0 +1,100 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying presearch ================="); + log(res); + log("================= Deploying presearch ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access presearch via the browser using: http://newVMS5.${res[0].env.PRESEARCH_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/presearch-v2.3.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + PRESEARCH_REGISTRATION_CODE: "e5083a8d0a6362c6cf7a3078bfac81e3", + PRESEARCH_BACKUP_PRI_KEY: "", + PRESEARCH_BACKUP_PUB_KEY: "", + PRESEARCH_WEBSERVER_HOSTNAME: "gent01.dev.grid.tf", + }, + }, + ], + metadata: "", + description: "presearch machine", + }; + + //Deploy presearch + // await deploy(grid3, vms); + + //Get the deployment + // await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/subsquid.ts b/packages/grid_client/scripts/subsquid.ts new file mode 100644 index 0000000000..4e4fd9e9f4 --- /dev/null +++ b/packages/grid_client/scripts/subsquid.ts @@ -0,0 +1,98 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying subsquid ================="); + log(res); + log("================= Deploying subsquid ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access subsquid via the browser using: http://newVMS5.${res[0].env.SUBSQUID_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/subsquid-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + CHAIN_ENDPOINT: "10.10.10.10", + SUBSQUID_WEBSERVER_HOSTNAME: "", + }, + }, + ], + metadata: "", + description: "subsquid machine", + }; + + //Deploy subsquid + // await deploy(grid3, vms); + + //Get the deployment + // await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/taiga.ts b/packages/grid_client/scripts/taiga.ts new file mode 100644 index 0000000000..6679780183 --- /dev/null +++ b/packages/grid_client/scripts/taiga.ts @@ -0,0 +1,100 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying Taiga ================="); + log(res); + log("================= Deploying Taiga ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access Taiga via the browser using: http://captain.${res[0].env.DOMAIN_NAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/grid3_taiga_docker-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + DOMAIN_NAME: "gent02.dev.grid.tf", + ADMIN_USERNAME: "test1", + ADMIN_PASSWORD: "123456", + ADMIN_EMAIL: "test123@gmail.com", + }, + }, + ], + metadata: "", + description: "taiga deployment machine", + }; + + // Deploy Taiga + await deploy(grid3, vms); + + // Get the deployment + await getDeployment(grid3, vms.name); + + // Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/umbrel.ts b/packages/grid_client/scripts/umbrel.ts new file mode 100644 index 0000000000..df02f34b6c --- /dev/null +++ b/packages/grid_client/scripts/umbrel.ts @@ -0,0 +1,99 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying umbrel ================="); + log(res); + log("================= Deploying umbrel ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access umbrel via the browser using: http://newVMS5.${res[0].env.UMBREL_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/umbrel-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + USERNAME: "testtest", + PASSWORD: "123456", + UMBREL_DISK: "/umbrelDisk", + }, + }, + ], + metadata: "", + description: "umbrel machine", + }; + + //Deploy umbrel + // await deploy(grid3, vms); + + //Get the deployment + // await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/wordpress.ts b/packages/grid_client/scripts/wordpress.ts new file mode 100644 index 0000000000..2fe8ccd68b --- /dev/null +++ b/packages/grid_client/scripts/wordpress.ts @@ -0,0 +1,100 @@ +import { FilterOptions, MachinesModel } from "../src"; +import { config, getClient } from "./client_loader"; +import { log } from "./utils"; + +async function deploy(client, vms) { + try { + const res = await client.machines.deploy(vms); + log("================= Deploying umbrel ================="); + log(res); + log("================= Deploying umbrel ================="); + } catch (error) { + log("Error while Deploying the VM " + error); + } +} + +async function getDeployment(client, vms) { + try { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log(`You can access umbrel via the browser using: http://newVMS5.${res[0].env.UMBREL_WEBSERVER_HOSTNAME}`); + log("================= Getting deployment information ================="); + } catch (error) { + log("Error while getting the deployment " + error); + } +} + +async function cancel(client, vms) { + try { + const res = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(res); + log("================= Canceling the deployment ================="); + } catch (error) { + log("Error while canceling the deployment " + error); + } +} + +async function main() { + const grid3 = await getClient(); + + const vmQueryOptions: FilterOptions = { + cru: 4, + mru: 4, // GB + sru: 10, + farmId: 1, + }; + + const vms: MachinesModel = { + name: "newVMS5", + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "testvm", + node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId, + disks: [ + { + name: "wedDisk", + size: 8, + mountpoint: "/var/lib/docker", + }, + ], + public_ip: true, + public_ip6: false, + planetary: false, + mycelium: true, + cpu: 4, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/tf-wordpress-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + MYSQL_USER: "testtest", + MYSQL_PASSWORD: "123456", + ADMIN_EMAIL: "test@gmail.com", + WP_URL: "", + }, + }, + ], + metadata: "", + description: "wordpress machine", + }; + + //Deploy umbrel + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms.name); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name: vms.name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/tests/modules/casperlabs.test.ts b/packages/grid_client/tests/modules/casperlabs.test.ts new file mode 100644 index 0000000000..016b4509d8 --- /dev/null +++ b/packages/grid_client/tests/modules/casperlabs.test.ts @@ -0,0 +1,170 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy casperlabs", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy casperlabs + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the casperlabs on. + - Deploy the casperlabs solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the casperlabs solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'casperlabs'}"; + const description = "test deploying casperlabs via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/casperlabs-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + CASPERLABS_HOSTNAME: "", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("casperlabs: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/discourse.test.ts b/packages/grid_client/tests/modules/discourse.test.ts new file mode 100644 index 0000000000..a3dcec9980 --- /dev/null +++ b/packages/grid_client/tests/modules/discourse.test.ts @@ -0,0 +1,177 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy a discourse", async () => { + /********************************************** + test suite: grid3_client_ts (automated) + test cases: tc - Deploy a discourse + scenario: + - generate test data/vm config. + - select a node to deploy the vm on. + - deploy the discourse solution. + - assert that the generated data matches + the deployment details. + - ssh to the vm and verify that you can + access it. + - assert that the environment variables + were passed successfully to the discourse + **********************************************/ + + //test data + let cpu = generateint(1, 4); + let memory = generateint(256, 4096); + let rootfssize = generateint(2, 5); + const deploymentname = generatestring(15); + const networkname = generatestring(15); + const vmname = generatestring(15); + const disks = []; + const publicip = false; + const iprangeclassa = "10." + generateint(1, 255) + ".0.0/16"; + const iprangeclassb = "172." + generateint(16, 31) + ".0.0/16"; + const iprangeclassc = "192.168.0.0/16"; + const iprange = randomchoice([iprangeclassa, iprangeclassb, iprangeclassc]); + const metadata = "{'deploymenttype': 'discourse'}"; + const description = "test deploying discourse via ts grid3 client"; + const envvarvalue = generatestring(30); + + //node selection + let nodes; + try { + nodes = await gridclient.capacity.filternodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfssize, + farmid: 1, + availablefor: await gridclient.twins.get_my_twin_id(), + } as filteroptions); + } catch (error) { + //log the resources that were not found. + log("a node was not found with the generated resources." + error); + log("regenerating test data with lower resources...."); + + //generate lower resources. + cpu = generateint(1, cpu); + memory = generateint(256, memory); + rootfssize = generateint(2, rootfssize); + + //search for another node with lower resources. + nodes = await gridclient.capacity.filternodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfssize, + farmid: 1, + availablefor: await gridclient.twins.get_my_twin_id(), + } as filteroptions); + } + const nodeid = await getonlinenode(nodes); + if (nodeid == -1) throw new error("no nodes available to complete this test"); + + //vm model + const vms: machinesmodel = { + name: deploymentname, + network: { + name: networkname, + ip_range: iprange, + }, + machines: [ + { + name: vmname, + node_id: nodeid, + cpu: cpu, + memory: memory, + rootfs_size: rootfssize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/forum-docker-v3.1.2.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicip, + planetary: true, + mycelium: true, + env: { + ssh_key: config.ssh_key, + test_key: envvarvalue, + DISCOURSE_HOSTNAME: "gent02.dev.grid.tf", + DISCOURSE_DEVELOPER_EMAILS: "test12@gmail.com", + DISCOURSE_SMTP_ADDRESS: "", + DISCOURSE_SMTP_PORT: "", + DISCOURSE_SMTP_ENABLE_START_TLS: "", + DISCOURSE_SMTP_USER_NAME: "", + DISCOURSE_SMTP_PASSWORD: "", + THREEBOT_PRIVATE_KEY: "", + FLASK_SECRET_KEY: generateString(6), + }, + solutionproviderid: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridclient.machines.deploy(vms); + log(res); + + //contracts assertions + expect(res.contracts.created).tohavelength(1); + expect(res.contracts.updated).tohavelength(0); + expect(res.contracts.deleted).tohavelength(0); + + const vmslist = await gridclient.machines.list(); + log(vmslist); + + //vm list assertions + expect(vmslist.length).tobegreaterthanorequal(1); + expect(vmslist).tocontain(vms.name); + + const result = await gridclient.machines.getobj(vms.name); + log(result); + + //vm assertions + expect(result[0].nodeid).tobe(nodeid); + expect(result[0].status).tobe("ok"); + expect(result[0].flist).tobe(vms.machines[0].flist); + expect(result[0].entrypoint).tobe(vms.machines[0].entrypoint); + expect(result[0].mounts).tohavelength(0); + expect(result[0].interfaces[0]["network"]).tobe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).tocontain(splitip(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).tomatch(ipregex); + expect(result[0].capacity["cpu"]).tobe(cpu); + expect(result[0].capacity["memory"]).tobe(memory); + expect(result[0].planetary).tobedefined(); + expect(result[0].publicip).tobenull(); + expect(result[0].metadata).tobe(metadata); + expect(result[0].description).tobe(description); + + const host = result[0].planetary; + const user = "root"; + + //ssh to the created vm + const ssh = await remoterun(host, user); + + try { + //verify that the added env var was successfully passed to the vm. + await ssh.execcommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).tocontain(envvarvalue); + }); + + //verify zinit services + await ssh.execcommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).tocontain("discourse: running"); + }); + } finally { + //disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/funkwhale.test.ts b/packages/grid_client/tests/modules/funkwhale.test.ts new file mode 100644 index 0000000000..7b8e30759f --- /dev/null +++ b/packages/grid_client/tests/modules/funkwhale.test.ts @@ -0,0 +1,172 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - VM: Deploy a funkwhale", async () => { + /********************************************** + test suite: grid3_client_ts (automated) + test cases: tc - deploy a funkwhale + scenario: + - generate test data/vm config. + - select a node to deploy the vm on. + - deploy the funkwhale solution. + - assert that the generated data matches + the deployment details. + - ssh to the vm and verify that you can + access it. + - assert that the environment variables + were passed successfully to the funkwhale + **********************************************/ + + //test data + let cpu = generateint(1, 4); + let memory = generateint(256, 4096); + let rootfssize = generateint(2, 5); + const deploymentname = generatestring(15); + const networkname = generatestring(15); + const vmname = generatestring(15); + const disks = []; + const publicip = false; + const iprangeclassa = "10." + generateint(1, 255) + ".0.0/16"; + const iprangeclassb = "172." + generateint(16, 31) + ".0.0/16"; + const iprangeclassc = "192.168.0.0/16"; + const iprange = randomchoice([iprangeclassa, iprangeclassb, iprangeclassc]); + const metadata = "{'deploymenttype': 'funkwhale'}"; + const description = "test deploying funkwhale via ts grid3 client"; + const envvarvalue = generatestring(30); + + //node selection + let nodes; + try { + nodes = await gridclient.capacity.filternodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfssize, + farmid: 1, + availablefor: await gridclient.twins.get_my_twin_id(), + } as filteroptions); + } catch (error) { + //log the resources that were not found. + log("a node was not found with the generated resources." + error); + log("regenerating test data with lower resources...."); + + //generate lower resources. + cpu = generateint(1, cpu); + memory = generateint(256, memory); + rootfssize = generateint(2, rootfssize); + + //search for another node with lower resources. + nodes = await gridclient.capacity.filternodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfssize, + farmid: 1, + availablefor: await gridclient.twins.get_my_twin_id(), + } as filteroptions); + } + const nodeid = await getonlinenode(nodes); + if (nodeid == -1) throw new error("no nodes available to complete this test"); + + //vm model + const vms: machinesmodel = { + name: deploymentname, + network: { + name: networkname, + ip_range: iprange, + }, + machines: [ + { + name: vmname, + node_id: nodeid, + cpu: cpu, + memory: memory, + rootfs_size: rootfssize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/funkwhale-dec21.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicip, + planetary: true, + mycelium: true, + env: { + ssh_key: config.ssh_key, + test_key: envvarvalue, + DJANGO_SUPERUSER_EMAIL: "test@gmail.com", + DJANGO_SUPERUSER_USERNAME: "", + DJANGO_SUPERUSER_PASSWORD: "test123", + FUNKWHALE_HOSTNAME: "gent02.dev.grid.tf", + }, + solutionproviderid: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridclient.machines.deploy(vms); + log(res); + + //contracts assertions + expect(res.contracts.created).tohavelength(1); + expect(res.contracts.updated).tohavelength(0); + expect(res.contracts.deleted).tohavelength(0); + + const vmslist = await gridclient.machines.list(); + log(vmslist); + + //vm list assertions + expect(vmslist.length).tobegreaterthanorequal(1); + expect(vmslist).tocontain(vms.name); + + const result = await gridclient.machines.getobj(vms.name); + log(result); + + //vm assertions + expect(result[0].nodeid).tobe(nodeid); + expect(result[0].status).tobe("ok"); + expect(result[0].flist).tobe(vms.machines[0].flist); + expect(result[0].entrypoint).tobe(vms.machines[0].entrypoint); + expect(result[0].mounts).tohavelength(0); + expect(result[0].interfaces[0]["network"]).tobe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).tocontain(splitip(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).tomatch(ipregex); + expect(result[0].capacity["cpu"]).tobe(cpu); + expect(result[0].capacity["memory"]).tobe(memory); + expect(result[0].planetary).tobedefined(); + expect(result[0].publicip).tobenull(); + expect(result[0].metadata).tobe(metadata); + expect(result[0].description).tobe(description); + + const host = result[0].planetary; + const user = "root"; + + //ssh to the created vm + const ssh = await remoterun(host, user); + + try { + //verify that the added env var was successfully passed to the vm. + await ssh.execcommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).tocontain(envvarvalue); + }); + + //verify zinit services + await ssh.execcommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).tocontain("funkwhale: running"); + }); + } finally { + //disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/mattermost.test.ts b/packages/grid_client/tests/modules/mattermost.test.ts new file mode 100644 index 0000000000..f6a050d9ea --- /dev/null +++ b/packages/grid_client/tests/modules/mattermost.test.ts @@ -0,0 +1,172 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy a mattermost", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy a mattermost + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the mattermost on. + - Deploy the mattermost. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the mattermost solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'matermost'}"; + const description = "test deploying matermost via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/mattermost-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + MATTERMOST_DOMAIN: "gent02.dev.grid.tf", + SITE_URL: "https://gent02.dev.grid.tf", + DB_PASSWORD: "", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("mattermost: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/nodepilot.test.ts b/packages/grid_client/tests/modules/nodepilot.test.ts new file mode 100644 index 0000000000..a6cf5bcaa5 --- /dev/null +++ b/packages/grid_client/tests/modules/nodepilot.test.ts @@ -0,0 +1,170 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy nodepilot", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy nodepilot + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the nodepilot on. + - Deploy the nodepilot solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the nodepilot solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'nodepilot'}"; + const description = "test deploying nodepilot via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/nodepilot-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + NODEPILOT_HOSTNAME: "", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("nodepilot: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/owncloud.test.ts b/packages/grid_client/tests/modules/owncloud.test.ts new file mode 100644 index 0000000000..d5ccf6934c --- /dev/null +++ b/packages/grid_client/tests/modules/owncloud.test.ts @@ -0,0 +1,172 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy owncloud", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy owncloud + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the owncloud on. + - Deploy the owncloud solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the owncloud solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'owncloud'}"; + const description = "test deploying owncloud via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/owncloud-10.9.1.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + OWNCLOUD_ADMIN_USERNAME: "test1", + OWNCLOUD_ADMIN_PASSWORD: "123456", + OWNCLOUD_DOMAIN: "gent01.dev.grid.tf", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("owncloud: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/peertube.test.ts b/packages/grid_client/tests/modules/peertube.test.ts new file mode 100644 index 0000000000..e3eb0ba7d9 --- /dev/null +++ b/packages/grid_client/tests/modules/peertube.test.ts @@ -0,0 +1,171 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC1228 - VM: Deploy a peertube", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy a peertube + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the VM on. + - Deploy the peertube. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'peertube'}"; + const description = "test deploying peertube via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/peertube-v3.1.1.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + PEERTUBE_ADMIN_EMAIL: "test@gmail.com", + PT_INITIAL_ROOT_PASSWORD: "test123", + PEERTUBE_WEBSERVER_HOSTNAME: "gent01.dev.grid.tf", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("peertube: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/presearch.test.ts b/packages/grid_client/tests/modules/presearch.test.ts new file mode 100644 index 0000000000..947ec54f1d --- /dev/null +++ b/packages/grid_client/tests/modules/presearch.test.ts @@ -0,0 +1,173 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy presearch", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy presearch + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the presearch on. + - Deploy the presearch solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the presearch solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'presearch'}"; + const description = "test deploying presearch via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/presearch-v2.3.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + PRESEARCH_REGISTRATION_CODE: "e5083a8d0a6362c6cf7a3078bfac81e3", + PRESEARCH_BACKUP_PRI_KEY: "", + PRESEARCH_BACKUP_PUB_KEY: "", + PRESEARCH_WEBSERVER_HOSTNAME: "gent01.dev.grid.tf", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("prenode: Success"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/subsquid.test.ts b/packages/grid_client/tests/modules/subsquid.test.ts new file mode 100644 index 0000000000..fbf41d39da --- /dev/null +++ b/packages/grid_client/tests/modules/subsquid.test.ts @@ -0,0 +1,173 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy subsquid", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy subsquid + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the subsquid on. + - Deploy the subsquid solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the subsquid solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'subsquid'}"; + const description = "test deploying subsquid via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/subsquid-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + SUBSQUID_WEBSERVER_HOSTNAME: "gent01.dev.grid.tf", + SUBSQUID_REGISTRATION_CODE: "e5083a8d0a6362c6cf7a3078bfac81e3", + SUBSQUID_BACKUP_PRI_KEY: "", + SUBSQUID_BACKUP_PUB_KEY: "", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("subsquid: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/taiga.test.ts b/packages/grid_client/tests/modules/taiga.test.ts new file mode 100644 index 0000000000..3f1b8e3405 --- /dev/null +++ b/packages/grid_client/tests/modules/taiga.test.ts @@ -0,0 +1,173 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy a taiga", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy a taiga + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the taiga on. + - Deploy the taiga. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the taiga. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'taiga'}"; + const description = "test deploying taiga via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/grid3_taiga_docker-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + DOMAIN_NAME: "gent02.dev.grid.tf", + ADMIN_USERNAME: "test1", + ADMIN_PASSWORD: "123456", + ADMIN_EMAIL: "test123@gmail.com", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("taiga: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/umbrel.test.ts b/packages/grid_client/tests/modules/umbrel.test.ts new file mode 100644 index 0000000000..2aed9a602e --- /dev/null +++ b/packages/grid_client/tests/modules/umbrel.test.ts @@ -0,0 +1,170 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy umbrel", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy umbrel + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the umbrel on. + - Deploy the umbrel solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the umbrel solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'umbrel'}"; + const description = "test deploying umbrel via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/umbrel-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + UMBREL_HOSTNAME: "", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("umbrel: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +}); diff --git a/packages/grid_client/tests/modules/wordpress.test.ts b/packages/grid_client/tests/modules/wordpress.test.ts new file mode 100644 index 0000000000..66f5b81321 --- /dev/null +++ b/packages/grid_client/tests/modules/wordpress.test.ts @@ -0,0 +1,173 @@ +import { FilterOptions, generateString, GridClient, MachineModel, MachinesModel, randomChoice } from "../../src"; +import { config, getClient } from "../client_loader"; +import { bytesToGB, generateInt, getOnlineNode, log, RemoteRun, splitIP } from "../utils"; + +jest.setTimeout(300000); + +let gridClient: GridClient; + +beforeAll(async () => { + return (gridClient = await getClient()); +}); + +//Private IP Regex +const ipRegex = /(^127\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.168\.)/; + +test("TC - Deploy wordpress", async () => { + /********************************************** + Test Suite: Grid3_Client_TS (Automated) + Test Cases: TC - Deploy wordpress + Scenario: + - Generate Test Data/VM Config. + - Select a Node To Deploy the wordpress on. + - Deploy the wordpress solution. + - Assert that the generated data matches + the deployment details. + - SSH to the VM and Verify that you can + access it. + - Assert that the Environment Variables + Were passed successfully to the VM + - Verify the resources of the wordpress solution. + **********************************************/ + + //Test Data + let cpu = generateInt(1, 4); + let memory = generateInt(256, 4096); + let rootfsSize = generateInt(2, 5); + const deploymentName = generateString(15); + const networkName = generateString(15); + const vmName = generateString(15); + const disks = []; + const publicIP = false; + const ipRangeClassA = "10." + generateInt(1, 255) + ".0.0/16"; + const ipRangeClassB = "172." + generateInt(16, 31) + ".0.0/16"; + const ipRangeClassC = "192.168.0.0/16"; + const ipRange = randomChoice([ipRangeClassA, ipRangeClassB, ipRangeClassC]); + const metadata = "{'deploymentType': 'wordpress'}"; + const description = "test deploying wordpress via ts grid3 client"; + const envVarValue = generateString(30); + + //Node Selection + let nodes; + try { + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } catch (error) { + //Log the resources that were not found. + log("A Node was not found with the generated resources." + error); + log("Regenerating test data with lower resources...."); + + //Generate lower resources. + cpu = generateInt(1, cpu); + memory = generateInt(256, memory); + rootfsSize = generateInt(2, rootfsSize); + + //Search for another node with lower resources. + nodes = await gridClient.capacity.filterNodes({ + cru: cpu, + mru: memory / 1024, + sru: rootfsSize, + farmId: 1, + availableFor: await gridClient.twins.get_my_twin_id(), + } as FilterOptions); + } + const nodeId = await getOnlineNode(nodes); + if (nodeId == -1) throw new Error("no nodes available to complete this test"); + + //VM Model + const vms: MachinesModel = { + name: deploymentName, + network: { + name: networkName, + ip_range: ipRange, + }, + machines: [ + { + name: vmName, + node_id: nodeId, + cpu: cpu, + memory: memory, + rootfs_size: rootfsSize, + disks: disks, + flist: "https://hub.grid.tf/tf-official-apps/wordpress-latest.flist", + entrypoint: "/sbin/zinit init", + public_ip: publicIP, + planetary: true, + mycelium: true, + env: { + SSH_KEY: config.ssh_key, + Test_KEY: envVarValue, + MYSQL_USER: "testtest", + MYSQL_PASSWORD: "123456", + ADMIN_EMAIL: "test@gmail.com", + WP_URL: "", + }, + solutionProviderId: null, + }, + ], + metadata: metadata, + description: description, + }; + + const res = await gridClient.machines.deploy(vms); + log(res); + + //Contracts Assertions + expect(res.contracts.created).toHaveLength(1); + expect(res.contracts.updated).toHaveLength(0); + expect(res.contracts.deleted).toHaveLength(0); + + const vmsList = await gridClient.machines.list(); + log(vmsList); + + //VM List Assertions + expect(vmsList.length).toBeGreaterThanOrEqual(1); + expect(vmsList).toContain(vms.name); + + const result = await gridClient.machines.getObj(vms.name); + log(result); + + //VM Assertions + expect(result[0].nodeId).toBe(nodeId); + expect(result[0].status).toBe("ok"); + expect(result[0].flist).toBe(vms.machines[0].flist); + expect(result[0].entrypoint).toBe(vms.machines[0].entrypoint); + expect(result[0].mounts).toHaveLength(0); + expect(result[0].interfaces[0]["network"]).toBe(vms.network.name); + expect(result[0].interfaces[0]["ip"]).toContain(splitIP(vms.network.ip_range)); + expect(result[0].interfaces[0]["ip"]).toMatch(ipRegex); + expect(result[0].capacity["cpu"]).toBe(cpu); + expect(result[0].capacity["memory"]).toBe(memory); + expect(result[0].planetary).toBeDefined(); + expect(result[0].publicIP).toBeNull(); + expect(result[0].metadata).toBe(metadata); + expect(result[0].description).toBe(description); + + const host = result[0].planetary; + const user = "root"; + + //SSH to the Created VM + const ssh = await RemoteRun(host, user); + + try { + //Verify that the added env var was successfully passed to the VM. + await ssh.execCommand("cat /proc/1/environ").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain(envVarValue); + }); + + //verify zinit services + await ssh.execCommand("zinit").then(async function (result) { + log(result.stdout); + expect(result.stdout).toContain("wordpress: Running"); + }); + } finally { + //Disconnect from the machine + await ssh.dispose(); + } +});