Skip to content

Commit

Permalink
refactor: use generateBasicVm in all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SalmaElsoly committed Oct 16, 2024
1 parent 639b1ac commit 82d0565
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 182 deletions.
57 changes: 11 additions & 46 deletions grid-client/integration_tests/batch_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,67 +46,32 @@ func TestBatchK8sDeployment(t *testing.T) {
require.NoError(t, err)
})

masterSeed1, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

masterSeed2, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

workerNodeSeed1, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

workerNodeSeed2, err := workloads.RandomMyceliumIPSeed()
masterVM1, err := generateBasicVM(generateRandString(10), nodeID1, network.Name, "")
require.NoError(t, err)

master1 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID1,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
MyceliumIPSeed: masterSeed1,
},
VM: &masterVM1,
DiskSizeGB: 1,
}
masterVM2, err := generateBasicVM(generateRandString(10), nodeID2, network.Name, "")
require.NoError(t, err)

master2 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID2,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
MyceliumIPSeed: masterSeed2,
},
VM: &masterVM2,
DiskSizeGB: 1,
}
vm1, err := generateBasicVM(generateRandString(10), nodeID1, network.Name, "")
require.NoError(t, err)

workerNodeData1 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID1,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
MyceliumIPSeed: workerNodeSeed1,
},
VM: &vm1,
DiskSizeGB: 1,
}
vm2, err := generateBasicVM(generateRandString(10), nodeID2, network.Name, "")
require.NoError(t, err)

workerNodeData2 := workloads.K8sNode{
VM: &workloads.VM{
Name: generateRandString(10),
NetworkName: network.Name,
NodeID: nodeID2,
Planetary: true,
CPU: minCPU,
MemoryMB: minMemory * 1024,
MyceliumIPSeed: workerNodeSeed2,
},
VM: &vm2,
DiskSizeGB: 1,
}

Expand Down
42 changes: 9 additions & 33 deletions grid-client/integration_tests/k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,51 +77,27 @@ func TestK8sDeployment(t *testing.T) {
err = tfPluginClient.NetworkDeployer.Cancel(context.Background(), &network)
require.NoError(t, err)
})
masterSeed, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

workerNodeSeed1, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

workerNodeSeed2, err := workloads.RandomMyceliumIPSeed()
masterVM, err := generateBasicVM(fmt.Sprintf("master_%s", generateRandString(5)), masterNodeID, network.Name, "")
require.NoError(t, err)

master := workloads.K8sNode{
VM: &workloads.VM{
Name: fmt.Sprintf("master_%s", generateRandString(5)),
NodeID: masterNodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
MyceliumIPSeed: masterSeed,
},
VM: &masterVM,
DiskSizeGB: 1,
}

vm1, err := generateBasicVM(fmt.Sprintf("worker1_%s", generateRandString(5)), workerNodeID, network.Name, "")
require.NoError(t, err)

workerNodeData1 := workloads.K8sNode{
VM: &workloads.VM{
Name: fmt.Sprintf("worker1_%s", generateRandString(5)),
NodeID: workerNodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
MyceliumIPSeed: workerNodeSeed1,
},
VM: &vm1,
DiskSizeGB: 1,
}
vm2, err := generateBasicVM(fmt.Sprintf("worker2_%s", generateRandString(5)), workerNodeID, network.Name, "")
require.NoError(t, err)

workerNodeData2 := workloads.K8sNode{
VM: &workloads.VM{
Name: fmt.Sprintf("worker2_%s", generateRandString(5)),
NodeID: workerNodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Planetary: true,
MyceliumIPSeed: workerNodeSeed2,
},
VM: &vm2,
DiskSizeGB: 1,
}

Expand Down
5 changes: 2 additions & 3 deletions grid-client/integration_tests/qsfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ func TestQSFSDeployment(t *testing.T) {
}

vm, err := generateBasicVM("vm", nodeID, network.Name, publicKey)
if err != nil {
t.Skipf("vm creation failed: %v", err)
}
require.NoError(t, err)

vm.Mounts = []workloads.Mount{
{Name: qsfs.Name, MountPoint: "/qsfs"},
}
Expand Down
50 changes: 14 additions & 36 deletions grid-client/integration_tests/two_vms_same_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,43 +39,21 @@ func TestTwoVMsSameNetworkWithPublicIPV6(t *testing.T) {
network, err := generateBasicNetwork([]uint32{nodeID})
require.NoError(t, err)

myCeliumSeed1, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

vm1 := workloads.VM{
Name: "vm1",
NodeID: nodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Flist: "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
MyceliumIPSeed: myCeliumSeed1,
RootfsSizeMB: minRootfs * 1024,
PublicIP6: true,
}
ubuntuFlist := "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist"

myCeliumSeed2, err := workloads.RandomMyceliumIPSeed()
require.NoError(t, err)

vm2 := workloads.VM{
Name: "vm2",
NodeID: nodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Flist: "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
MyceliumIPSeed: myCeliumSeed2,
RootfsSizeMB: minRootfs * 1024,
PublicIP6: true,
}
vm1, err := generateBasicVM("vm1", nodeID, network.Name, publicKey)
require.NoError(t, err)

vm1.Flist = ubuntuFlist
vm1.RootfsSizeMB = minRootfs * 1024
vm1.PublicIP6 = true

vm2, err := generateBasicVM("vm2", nodeID, network.Name, publicKey)
require.NoError(t, err)

vm2.Flist = ubuntuFlist
vm2.RootfsSizeMB = minRootfs * 1024
vm2.PublicIP6 = true

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
require.NoError(t, err)
Expand Down
28 changes: 9 additions & 19 deletions grid-client/integration_tests/vm_gpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,27 +60,17 @@ func TestVMWithGPUDeployment(t *testing.T) {
SizeGB: 20,
}

myCeliumSeed, err := workloads.RandomMyceliumIPSeed()
vm, err := generateBasicVM("gpu", nodeID, network.Name, publicKey)
require.NoError(t, err)

vm := workloads.VM{
Name: "gpu",
NodeID: nodeID,
NetworkName: network.Name,
CPU: 4,
MemoryMB: 1024 * 8,
RootfsSizeMB: minRootfs * 1024,
Planetary: true,
GPUs: ConvertGPUsToStr(gpus),
Flist: "https://hub.grid.tf/tf-official-vms/ubuntu-22.04.flist",
Entrypoint: "/init.sh",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
Mounts: []workloads.Mount{
{Name: disk.Name, MountPoint: "/data"},
},
MyceliumIPSeed: myCeliumSeed,
vm.CPU = 4
vm.MemoryMB = 1024 * 8
vm.RootfsSizeMB = minRootfs * 1024
vm.GPUs = ConvertGPUsToStr(gpus)
vm.Flist = "https://hub.grid.tf/tf-official-vms/ubuntu-22.04.flist"
vm.Entrypoint = "/init.sh"
vm.Mounts = []workloads.Mount{
{Name: disk.Name, MountPoint: "/data"},
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
Expand Down
22 changes: 4 additions & 18 deletions grid-client/integration_tests/vm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,12 @@ func TestVMDeployment(t *testing.T) {
network, err := generateBasicNetwork([]uint32{nodeID})
require.NoError(t, err)

myCeliumSeed, err := workloads.RandomMyceliumIPSeed()
vm, err := generateBasicVM("vm", nodeID, network.Name, publicKey)
require.NoError(t, err)

vm := workloads.VM{
Name: "vm",
NodeID: nodeID,
NetworkName: network.Name,
IP: "10.20.2.5",
CPU: minCPU,
MemoryMB: minMemory * 1024,
RootfsSizeMB: minRootfs * 1024,
PublicIP: true,
Planetary: true,
Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
MyceliumIPSeed: myCeliumSeed,
}
vm.IP = "10.20.2.5"
vm.RootfsSizeMB = minRootfs * 1024
vm.PublicIP = true

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
require.NoError(t, err)
Expand Down
23 changes: 5 additions & 18 deletions grid-client/integration_tests/vm_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,13 @@ func TestVMWithVolume(t *testing.T) {
Name: "volume",
SizeGB: 1,
}
myCeliumSeed, err := workloads.RandomMyceliumIPSeed()

vm, err := generateBasicVM("vm", nodeID, network.Name, publicKey)
require.NoError(t, err)

vm := workloads.VM{
Name: "vm",
NodeID: nodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
RootfsSizeMB: minRootfs * 1024,
Planetary: true,
Flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
Entrypoint: "/sbin/zinit init",
EnvVars: map[string]string{
"SSH_KEY": publicKey,
},
Mounts: []workloads.Mount{
{Name: volume.Name, MountPoint: "/volume"},
},
MyceliumIPSeed: myCeliumSeed,
vm.RootfsSizeMB = minRootfs * 1024
vm.Mounts = []workloads.Mount{
{Name: volume.Name, MountPoint: "/volume"},
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
Expand Down
13 changes: 4 additions & 9 deletions grid-client/integration_tests/vms_private_ips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,10 @@ func TestDeploymentsDeploy(t *testing.T) {
network, err := generateBasicNetwork([]uint32{nodeID})
require.NoError(t, err)

vm1 := workloads.VM{
Name: vm1Name,
NodeID: nodeID,
NetworkName: network.Name,
CPU: minCPU,
MemoryMB: minMemory * 1024,
Flist: "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist",
Entrypoint: "/sbin/zinit init",
}
vm1, err := generateBasicVM(vm1Name, nodeID, network.Name, "")
require.NoError(t, err)

vm1.Flist = "https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist"

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
if err != nil {
Expand Down

0 comments on commit 82d0565

Please sign in to comment.