diff --git a/sdl/_testdata/storageClass6.yaml b/sdl/_testdata/storageClass6.yaml new file mode 100644 index 0000000000..fccfb944c9 --- /dev/null +++ b/sdl/_testdata/storageClass6.yaml @@ -0,0 +1,53 @@ +--- +version: "2.0" +services: + web: + image: nginx + expose: + - port: 80 + accept: + - ahostname.com + to: + - global: true + - port: 12345 + to: + - global: true + proto: udp + params: + storage: + configs: + mount: /test +profiles: + compute: + web: + resources: + cpu: + units: "100m" + memory: + size: "128Mi" + storage: + - size: "1Gi" + - size: 1Gi + name: configs + attributes: + persistent: true + placement: + westcoast: + attributes: + region: us-west + signedBy: + anyOf: + - 1 + - 2 + allOf: + - 3 + - 4 + pricing: + web: + denom: uakt + amount: 50 +deployment: + web: + westcoast: + profile: web + count: 1 diff --git a/sdl/v2_test.go b/sdl/v2_test.go index 897db36293..859d621f4e 100644 --- a/sdl/v2_test.go +++ b/sdl/v2_test.go @@ -798,3 +798,143 @@ func TestV2ParseServiceMix2(t *testing.T) { }, }, mani.GetGroups()[0]) } + +func TestV2ParseStorageName(t *testing.T) { + sdl, err := ReadFile("./_testdata/storageClass6.yaml") + require.NoError(t, err) + + groups, err := sdl.DeploymentGroups() + require.NoError(t, err) + assert.Len(t, groups, 1) + + group := groups[0] + assert.Len(t, group.GetResourceUnits(), 1) + assert.Len(t, group.Requirements.Attributes, 1) + + assert.Equal(t, atypes.Attribute{ + Key: "region", + Value: "us-west", + }, group.Requirements.Attributes[0]) + + assert.Equal(t, dtypes.ResourceUnits{ + { + Count: 1, + Resources: atypes.Resources{ + ID: 1, + CPU: &atypes.CPU{ + Units: atypes.NewResourceValue(randCPU), + }, + GPU: &atypes.GPU{ + Units: atypes.NewResourceValue(0), + }, + Memory: &atypes.Memory{ + Quantity: atypes.NewResourceValue(randMemory), + }, + Storage: atypes.Volumes{ + { + Name: "default", + Quantity: atypes.NewResourceValue(randStorage), + }, + { + Name: "configs", + Quantity: atypes.NewResourceValue(randStorage), + Attributes: atypes.Attributes{ + { + Key: "class", + Value: "default", + }, + { + Key: "persistent", + Value: "true", + }, + }, + }, + }, + Endpoints: []atypes.Endpoint{ + { + Kind: atypes.Endpoint_SHARED_HTTP, + }, + { + Kind: atypes.Endpoint_RANDOM_PORT, + }, + }, + }, + Price: AkashDecCoin(t, 50), + }, + }, group.GetResourceUnits()) + + mani, err := sdl.Manifest() + require.NoError(t, err) + + assert.Len(t, mani.GetGroups(), 1) + + assert.Equal(t, manifest.Group{ + Name: "westcoast", + Services: []manifest.Service{ + { + Name: "web", + Image: "nginx", + Resources: atypes.Resources{ + ID: 1, + CPU: &atypes.CPU{ + Units: atypes.NewResourceValue(100), + }, + GPU: &atypes.GPU{ + Units: atypes.NewResourceValue(0), + }, + Memory: &atypes.Memory{ + Quantity: atypes.NewResourceValue(128 * unit.Mi), + }, + Storage: atypes.Volumes{ + { + Name: "default", + Quantity: atypes.NewResourceValue(1 * unit.Gi), + }, + { + Name: "configs", + Quantity: atypes.NewResourceValue(1 * unit.Gi), + Attributes: atypes.Attributes{ + { + Key: "class", + Value: "default", + }, + { + Key: "persistent", + Value: "true", + }, + }, + }, + }, + Endpoints: []atypes.Endpoint{ + { + Kind: atypes.Endpoint_SHARED_HTTP, + }, + { + Kind: atypes.Endpoint_RANDOM_PORT, + }, + }, + }, + Params: &manifest.ServiceParams{ + Storage: []manifest.StorageParams{ + { + Name: "configs", + Mount: "/test", + ReadOnly: false, + }, + }, + }, + Count: 1, + Expose: []manifest.ServiceExpose{ + { + Port: 80, Global: true, Proto: manifest.TCP, Hosts: []string{"ahostname.com"}, + HTTPOptions: defaultHTTPOptions, + }, + { + Port: 12345, Global: true, Proto: manifest.UDP, + HTTPOptions: defaultHTTPOptions, + }, + }, + }, + }, + }, mani.GetGroups()[0]) +}