88 "time"
99
1010 "github.com/stretchr/testify/assert"
11+ "github.com/threefoldtech/tfgrid-sdk-go/grid-client/deployer"
1112 "github.com/threefoldtech/tfgrid-sdk-go/grid-client/workloads"
13+ "github.com/threefoldtech/tfgrid-sdk-go/grid-proxy/pkg/types"
1214 "github.com/threefoldtech/zos/client"
1315 "github.com/threefoldtech/zos/pkg/gridtypes"
1416 "github.com/threefoldtech/zos/pkg/gridtypes/zos"
@@ -26,14 +28,27 @@ func TestVMWithGPUDeployment(t *testing.T) {
2628 tfPluginClient , err := setup ()
2729 assert .NoError (t , err )
2830
29- ctx , cancel := context .WithTimeout (context .Background (), 10 * time .Minute )
31+ ctx , cancel := context .WithTimeout (context .Background (), 5 * time .Minute )
3032 defer cancel ()
3133
32- publicKey , _ , err := GenerateSSHKeyPair ()
34+ publicKey , privateKey , err := GenerateSSHKeyPair ()
3335 assert .NoError (t , err )
3436
35- // TODO: add a filtered node
36- nodeID := uint32 (93 )
37+ twinID := uint64 (tfPluginClient .TwinID )
38+ nodeFilter := types.NodeFilter {
39+ Status : & statusUp ,
40+ FreeSRU : convertGBToBytes (20 ),
41+ FreeMRU : convertGBToBytes (8 ),
42+ RentedBy : & twinID ,
43+ HasGPU : & trueVal ,
44+ }
45+
46+ nodes , err := deployer .FilterNodes (ctx , tfPluginClient , nodeFilter )
47+ if err != nil {
48+ t .Skip ("no available nodes found" )
49+ }
50+ nodeID := uint32 (nodes [0 ].NodeID )
51+
3752 nodeClient , err := tfPluginClient .NcPool .GetNodeClient (tfPluginClient .SubstrateConn , nodeID )
3853 assert .NoError (t , err )
3954
@@ -51,18 +66,25 @@ func TestVMWithGPUDeployment(t *testing.T) {
5166 AddWGAccess : false ,
5267 }
5368
69+ disk := workloads.Disk {
70+ Name : "gpuDisk" ,
71+ SizeGB : 20 ,
72+ }
73+
5474 vm := workloads.VM {
5575 Name : "gpu" ,
56- Flist : "https://hub.grid.tf/tf-official-apps/threefoldtech- ubuntu-22.04.flist" ,
57- CPU : 2 ,
76+ Flist : "https://hub.grid.tf/tf-official-vms/ ubuntu-22.04.flist" ,
77+ CPU : 4 ,
5878 Planetary : true ,
59- Memory : 1024 ,
79+ Memory : 1024 * 8 ,
6080 GPUs : ConvertGPUsToStr (gpus ),
61- Entrypoint : "/sbin/zinit init" ,
81+ Entrypoint : "/init.sh " ,
6282 EnvVars : map [string ]string {
6383 "SSH_KEY" : publicKey ,
6484 },
65- IP : "10.20.2.5" ,
85+ Mounts : []workloads.Mount {
86+ {DiskName : disk .Name , MountPoint : "/data" },
87+ },
6688 NetworkName : network .Name ,
6789 }
6890
@@ -74,7 +96,7 @@ func TestVMWithGPUDeployment(t *testing.T) {
7496 assert .NoError (t , err )
7597 }()
7698
77- dl := workloads .NewDeployment ("gpu" , nodeID , "" , nil , network .Name , nil , nil , []workloads.VM {vm }, nil )
99+ dl := workloads .NewDeployment ("gpu" , nodeID , "" , nil , network .Name , []workloads. Disk { disk } , nil , []workloads.VM {vm }, nil )
78100 err = tfPluginClient .DeploymentDeployer .Deploy (ctx , & dl )
79101 assert .NoError (t , err )
80102
@@ -83,6 +105,12 @@ func TestVMWithGPUDeployment(t *testing.T) {
83105 assert .NoError (t , err )
84106 }()
85107
86- _ , err = tfPluginClient .State .LoadVMFromGrid (nodeID , vm .Name , dl .Name )
108+ vm , err = tfPluginClient .State .LoadVMFromGrid (nodeID , vm .Name , dl .Name )
109+ assert .NoError (t , err )
110+ assert .Equal (t , vm .GPUs , ConvertGPUsToStr (gpus ))
111+
112+ time .Sleep (30 * time .Second )
113+ output , err := RemoteRun ("root" , vm .YggIP , "lspci -v" , privateKey )
87114 assert .NoError (t , err )
115+ assert .Contains (t , string (output ), gpus [0 ].Vendor )
88116}
0 commit comments