Skip to content

Commit cac5ded

Browse files
authored
Merge pull request #570 from q384566678/blockIO-validate
validate: add weightDevice validation
2 parents 9d9aab0 + f48ae22 commit cac5ded

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

validate/validate.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,18 @@ func (v *Validator) CheckLinuxResources() (errs error) {
819819
}
820820
}
821821

822+
if r.BlockIO != nil && r.BlockIO.WeightDevice != nil {
823+
for i, weightDevice := range r.BlockIO.WeightDevice {
824+
if weightDevice.Weight == nil && weightDevice.LeafWeight == nil {
825+
errs = multierror.Append(errs,
826+
specerror.NewError(
827+
specerror.BlkIOWeightOrLeafWeightExist,
828+
fmt.Errorf("linux.resources.blockIO.weightDevice[%d] specifies neither weight nor leafWeight", i),
829+
rspec.Version))
830+
}
831+
}
832+
}
833+
822834
return
823835
}
824836

validate/validate_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,12 @@ func TestCheckProcess(t *testing.T) {
508508
}
509509

510510
func TestCheckLinux(t *testing.T) {
511+
weightDevices := []rspec.LinuxWeightDevice{
512+
rspec.LinuxWeightDevice{},
513+
}
514+
weightDevices[0].Major = 5
515+
weightDevices[0].Minor = 0
516+
511517
cases := []struct {
512518
val rspec.Spec
513519
expected specerror.Code
@@ -595,6 +601,19 @@ func TestCheckLinux(t *testing.T) {
595601
},
596602
expected: specerror.ReadonlyPathsAbs,
597603
},
604+
{
605+
val: rspec.Spec{
606+
Version: "1.0.0",
607+
Linux: &rspec.Linux{
608+
Resources: &rspec.LinuxResources{
609+
BlockIO: &rspec.LinuxBlockIO{
610+
WeightDevice: weightDevices,
611+
},
612+
},
613+
},
614+
},
615+
expected: specerror.BlkIOWeightOrLeafWeightExist,
616+
},
598617
}
599618
for _, c := range cases {
600619
v, err := NewValidator(&c.val, ".", false, "linux")

0 commit comments

Comments
 (0)