Skip to content

Commit

Permalink
Add volume workload
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelrahmanElawady committed May 22, 2024
1 parent 412f1c2 commit 19df5e8
Show file tree
Hide file tree
Showing 33 changed files with 1,339 additions and 70 deletions.
1,037 changes: 1,037 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions grid-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.10.2
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.10.2
github.com/threefoldtech/zos v0.5.6-0.20240226114056-364e04acbed3
github.com/threefoldtech/zos v0.5.6-0.20240516130312-5678a195142b
)

require (
Expand All @@ -27,7 +27,7 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/schema v1.3.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gtank/merlin v0.1.1 // indirect
Expand All @@ -44,7 +44,7 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240227171040-f2a20ee3e965 // indirect
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d // indirect
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.11.4 // indirect
github.com/vedhavyas/go-subkey v1.0.3 // indirect
golang.org/x/crypto v0.23.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions grid-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.3.0 h1:rbciOzXAx3IB8stEFnfTwO3sYa6EWlQk79XdyustPDA=
github.com/gorilla/schema v1.3.0/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
Expand Down Expand Up @@ -114,10 +114,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240227171040-f2a20ee3e965 h1:A4EF0webCGCQPym/uWrhhL6H3j/FKn60G99tR+Zl93o=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240227171040-f2a20ee3e965/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ=
github.com/threefoldtech/zos v0.5.6-0.20240226114056-364e04acbed3 h1:XsIUZFrT+pSn9w/HftxhYcE3mTohiejYlooNe8Eg+4U=
github.com/threefoldtech/zos v0.5.6-0.20240226114056-364e04acbed3/go.mod h1:FuTchJUh/PaESARVEYreXGBFaGA6SYDCvj7826xYEoM=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d h1:vWHR33VfphOahBlo3aGCE/eKPlfb4BCInhKidGkdp5s=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ=
github.com/threefoldtech/zos v0.5.6-0.20240516130312-5678a195142b h1:yf4qaq0Acw4+w7PfAbWF/Xzlb6G7O5haGY8QwRf0574=
github.com/threefoldtech/zos v0.5.6-0.20240516130312-5678a195142b/go.mod h1:bC3pYvaMRR5gJpWVr8u08RPHrJQwwXKPAw9LMMd1lGg=
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
Expand Down
4 changes: 2 additions & 2 deletions grid-cli/internal/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func DeployVM(ctx context.Context, t deployer.TFPluginClient, vm workloads.VM, m
mounts = append(mounts, mount)
}
vm.NetworkName = networkName
dl := workloads.NewDeployment(vm.Name, node, projectName, nil, networkName, mounts, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(vm.Name, node, projectName, nil, networkName, mounts, nil, []workloads.VM{vm}, nil, nil)

log.Info().Msg("deploying network")
err = t.NetworkDeployer.Deploy(ctx, &network)
Expand Down Expand Up @@ -123,7 +123,7 @@ func DeployGatewayFQDN(ctx context.Context, t deployer.TFPluginClient, gateway w

// DeployZDBs deploys multiple zdbs
func DeployZDBs(ctx context.Context, t deployer.TFPluginClient, projectName string, zdbs []workloads.ZDB, n int, node uint32) ([]workloads.ZDB, error) {
dl := workloads.NewDeployment(projectName, node, projectName, nil, "", nil, zdbs, nil, nil)
dl := workloads.NewDeployment(projectName, node, projectName, nil, "", nil, zdbs, nil, nil, nil)
log.Info().Msgf("deploying zdbs")
err := t.DeploymentDeployer.Deploy(ctx, &dl)
if err != nil {
Expand Down
15 changes: 14 additions & 1 deletion grid-client/deployer/deployment_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ func (d *DeploymentDeployer) GenerateVersionlessDeployments(ctx context.Context,
for _, disk := range dl.Disks {
newDl.Workloads = append(newDl.Workloads, disk.ZosWorkload())
}
for _, volume := range dl.Volumes {
newDl.Workloads = append(newDl.Workloads, volume.ZosWorkload())
}
for _, zdb := range dl.Zdbs {
newDl.Workloads = append(newDl.Workloads, zdb.ZosWorkload())
}
Expand Down Expand Up @@ -444,6 +447,7 @@ func (d *DeploymentDeployer) Sync(ctx context.Context, dl *workloads.Deployment)
zdbs := make([]workloads.ZDB, 0)
qsfs := make([]workloads.QSFS, 0)
disks := make([]workloads.Disk, 0)
volumes := make([]workloads.Volume, 0)

for _, w := range deployment.Workloads {
if !w.Result.State.IsOkay() {
Expand Down Expand Up @@ -484,15 +488,24 @@ func (d *DeploymentDeployer) Sync(ctx context.Context, dl *workloads.Deployment)
}

disks = append(disks, disk)
case zos.VolumeType:
volume, err := workloads.NewVolumeFromWorkload(&w)
if err != nil {
log.Error().Err(err).Msgf("error parsing volume")
continue
}

volumes = append(volumes, volume)
}
}

dl.Match(disks, qsfs, zdbs, vms)
dl.Match(disks, qsfs, zdbs, vms, volumes)

dl.Disks = disks
dl.QSFS = qsfs
dl.Zdbs = zdbs
dl.Vms = vms
dl.Volumes = volumes

return nil
}
6 changes: 3 additions & 3 deletions grid-client/deployer/deployment_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ func ExampleDeploymentDeployer_Deploy() {
return
}

dl := workloads.NewDeployment("vmdeployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment("vmdeployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -779,8 +779,8 @@ func ExampleDeploymentDeployer_BatchDeploy() {
return
}

d1 := workloads.NewDeployment("vm1deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm1}, nil)
d2 := workloads.NewDeployment("vm2deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm2}, nil)
d1 := workloads.NewDeployment("vm1deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm1}, nil, nil)
d2 := workloads.NewDeployment("vm2deployment", nodeID, "", nil, n.Name, nil, nil, []workloads.VM{vm2}, nil, nil)
err = tfPluginClient.DeploymentDeployer.BatchDeploy(context.Background(), []*workloads.Deployment{&d1, &d2})
if err != nil {
fmt.Println(err)
Expand Down
6 changes: 3 additions & 3 deletions grid-client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require (
github.com/rs/zerolog v1.32.0
github.com/sethvargo/go-retry v0.2.4
github.com/stretchr/testify v1.9.0
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240227171040-f2a20ee3e965
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d
github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.10.2
github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.11.4
github.com/threefoldtech/zos v0.5.6-0.20240226114056-364e04acbed3
github.com/threefoldtech/zos v0.5.6-0.20240516130312-5678a195142b
github.com/vedhavyas/go-subkey v1.0.3
golang.org/x/crypto v0.23.0
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa
Expand All @@ -35,7 +35,7 @@ require (
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/gomodule/redigo v2.0.0+incompatible // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions grid-client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa h1:Q75Upo5UN4JbPFURXZ8nLKYUvF85dyFRop/vQ0Rv+64=
github.com/google/gofuzz v1.1.1-0.20200604201612-c04b05f3adfa/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.3.0 h1:rbciOzXAx3IB8stEFnfTwO3sYa6EWlQk79XdyustPDA=
github.com/gorilla/schema v1.3.0/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
Expand Down Expand Up @@ -118,10 +118,10 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240227171040-f2a20ee3e965 h1:A4EF0webCGCQPym/uWrhhL6H3j/FKn60G99tR+Zl93o=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240227171040-f2a20ee3e965/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ=
github.com/threefoldtech/zos v0.5.6-0.20240226114056-364e04acbed3 h1:XsIUZFrT+pSn9w/HftxhYcE3mTohiejYlooNe8Eg+4U=
github.com/threefoldtech/zos v0.5.6-0.20240226114056-364e04acbed3/go.mod h1:FuTchJUh/PaESARVEYreXGBFaGA6SYDCvj7826xYEoM=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d h1:vWHR33VfphOahBlo3aGCE/eKPlfb4BCInhKidGkdp5s=
github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ=
github.com/threefoldtech/zos v0.5.6-0.20240516130312-5678a195142b h1:yf4qaq0Acw4+w7PfAbWF/Xzlb6G7O5haGY8QwRf0574=
github.com/threefoldtech/zos v0.5.6-0.20240516130312-5678a195142b/go.mod h1:bC3pYvaMRR5gJpWVr8u08RPHrJQwwXKPAw9LMMd1lGg=
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/batch_gateway_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestBatchGatewayNameDeployment(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID1, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID1, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions grid-client/integration_tests/batch_vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func TestBatchVMDeployment(t *testing.T) {
require.NoError(t, err)
})

dl1 := workloads.NewDeployment(fmt.Sprintf("dl1_%s", generateRandString(10)), nodeID1, "", nil, network1.Name, nil, nil, []workloads.VM{vm1}, nil)
dl2 := workloads.NewDeployment(fmt.Sprintf("dl2_%s", generateRandString(10)), nodeID2, "", nil, network2.Name, nil, nil, []workloads.VM{vm2}, nil)
dl1 := workloads.NewDeployment(fmt.Sprintf("dl1_%s", generateRandString(10)), nodeID1, "", nil, network1.Name, nil, nil, []workloads.VM{vm1}, nil, nil)
dl2 := workloads.NewDeployment(fmt.Sprintf("dl2_%s", generateRandString(10)), nodeID2, "", nil, network2.Name, nil, nil, []workloads.VM{vm2}, nil, nil)
err = tfPluginClient.DeploymentDeployer.BatchDeploy(context.Background(), []*workloads.Deployment{&dl1, &dl2})
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestDiskDeployment(t *testing.T) {
Description: "disk test",
}

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, "", []workloads.Disk{disk}, nil, nil, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, "", []workloads.Disk{disk}, nil, nil, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/gateway_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestGatewayNameDeployment(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/gatway_fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestGatewayFQDNDeployment(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions grid-client/integration_tests/qsfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestQSFSDeployment(t *testing.T) {
metaZDBs = append(metaZDBs, zdb)
}

dl1 := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, "", nil, append(dataZDBs, metaZDBs...), nil, nil)
dl1 := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, "", nil, append(dataZDBs, metaZDBs...), nil, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl1)
require.NoError(t, err)

Expand Down Expand Up @@ -169,7 +169,7 @@ func TestQSFSDeployment(t *testing.T) {
require.NoError(t, err)
})

dl2 := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, append(dataZDBs, metaZDBs...), []workloads.VM{vm}, []workloads.QSFS{qsfs})
dl2 := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, append(dataZDBs, metaZDBs...), []workloads.VM{vm}, []workloads.QSFS{qsfs}, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl2)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/two_vms_same_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestTwoVMsSameNetworkWithPublicIPV6(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm1, vm2}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm1, vm2}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/vm_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestVMWithTwoDisk(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, []workloads.Disk{disk1, disk2}, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, []workloads.Disk{disk1, disk2}, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/vm_gpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestVMWithGPUDeployment(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, []workloads.Disk{disk}, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, []workloads.Disk{disk}, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion grid-client/integration_tests/vm_public_ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestVMDeployment(t *testing.T) {
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil)
dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil, nil)
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

Expand Down
89 changes: 89 additions & 0 deletions grid-client/integration_tests/vm_volume_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package integration

import (
"context"
"fmt"
"strings"
"testing"

"github.com/stretchr/testify/require"
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/deployer"
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/workloads"
)

func TestVMWithVolume(t *testing.T) {
tfPluginClient, err := setup()
if err != nil {
t.Skipf("plugin creation failed: %v", err)
}

publicKey, privateKey, err := GenerateSSHKeyPair()
require.NoError(t, err)

nodes, err := deployer.FilterNodes(
context.Background(),
tfPluginClient,
generateNodeFilter(WithFreeSRU(3)),
[]uint64{*convertGBToBytes(2)},
nil,
[]uint64{*convertGBToBytes(minRootfs)},
1,
)
if err != nil {
t.Skipf("no available nodes found: %v", err)
}

nodeID := uint32(nodes[0].NodeID)

network := generateBasicNetwork([]uint32{nodeID})

volume := workloads.Volume{
Name: "volume",
SizeGB: 1,
}

vm := workloads.VM{
Name: "vm",
NetworkName: network.Name,
CPU: minCPU,
Memory: int(minMemory) * 1024,
RootfsSize: int(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{
{DiskName: volume.Name, MountPoint: "/volume"},
},
}

err = tfPluginClient.NetworkDeployer.Deploy(context.Background(), &network)
require.NoError(t, err)

t.Cleanup(func() {
err = tfPluginClient.NetworkDeployer.Cancel(context.Background(), &network)
require.NoError(t, err)
})

dl := workloads.NewDeployment(fmt.Sprintf("dl_%s", generateRandString(10)), nodeID, "", nil, network.Name, nil, nil, []workloads.VM{vm}, nil, []workloads.Volume{volume})
err = tfPluginClient.DeploymentDeployer.Deploy(context.Background(), &dl)
require.NoError(t, err)

t.Cleanup(func() {
err = tfPluginClient.DeploymentDeployer.Cancel(context.Background(), &dl)
require.NoError(t, err)
})

v, err := tfPluginClient.State.LoadVMFromGrid(context.Background(), nodeID, vm.Name, dl.Name)
require.NoError(t, err)
require.NotEmpty(t, v.PlanetaryIP)

resVolume, err := tfPluginClient.State.LoadVolumeFromGrid(context.Background(), nodeID, volume.Name, dl.Name)
require.NoError(t, err)
require.Equal(t, volume, resVolume)
res, err := RemoteRun("root", v.PlanetaryIP, "mount", privateKey)
require.NoError(t, err)
strings.Contains(res, "volume on /volume type virtiofs")
}
Loading

0 comments on commit 19df5e8

Please sign in to comment.