@@ -15,12 +15,12 @@ import (
1515 "strings"
1616 "time"
1717
18+ "github.com/containerd/continuity/testutil/loopback"
1819 "github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
1920 "github.com/docker/go-connections/nat"
2021 "github.com/moby/moby/api/types/blkiodev"
2122 . "github.com/onsi/ginkgo/v2"
2223 . "github.com/onsi/gomega"
23- "github.com/opencontainers/runtime-spec/specs-go"
2424 "github.com/runfinch/common-tests/command"
2525 "github.com/runfinch/common-tests/ffs"
2626 "github.com/runfinch/common-tests/option"
@@ -841,21 +841,16 @@ func ContainerCreate(opt *option.Option, pOpt util.NewOpt) {
841841 Skip ("Blkio settings are only supported on Linux" )
842842 }
843843
844- // Create dummy device paths
845- dummyDev1 := "/dev/dummy-zero1"
846- dummyDev2 := "/dev/dummy-zero2"
844+ // check if our nerdctl version is >= 2.1.5 or not
845+ // because nerdctl 2.1.5 saw changes in container inspect's hostconfig object
846+ // where Blkio fields were changed from LinuxBlkio* to Blkio* and instead of device
847+ // major:minor numbers, device paths are returned. See - https://github.com/containerd/nerdctl/pull/4512
848+ RequireNerdctlVersion (opt , ">=2.1.5" )
847849
848- // Create dummy devices (major number 1 for char devices)
849- mknodOpt1 , _ := pOpt ([]string {"mknod" , dummyDev1 , "c" , "1" , "5" })
850- command .Run (mknodOpt1 )
851- mknodOpt2 , _ := pOpt ([]string {"mknod" , dummyDev2 , "c" , "1" , "6" })
852- command .Run (mknodOpt2 )
853-
854- // Cleanup dummy devices after test
855- defer func () {
856- rmOpt , _ := pOpt ([]string {"rm" , "-f" , dummyDev1 , dummyDev2 })
857- command .Run (rmOpt )
858- }()
850+ // setup loop device
851+ lo , err := loopback .New (4096 )
852+ Expect (err ).Should (BeNil ())
853+ defer lo .Close ()
859854
860855 // define options
861856 options .Cmd = []string {"sleep" , "Infinity" }
@@ -864,40 +859,36 @@ func ContainerCreate(opt *option.Option, pOpt util.NewOpt) {
864859 // Create WeightDevice objects for input
865860 weightDevices := []* blkiodev.WeightDevice {
866861 {
867- Path : dummyDev1 ,
862+ Path : lo . Device ,
868863 Weight : 400 ,
869864 },
870- {
871- Path : dummyDev2 ,
872- Weight : 300 ,
873- },
874865 }
875866
876867 // Create ThrottleDevice objects for input
877868 readBpsDevices := []* blkiodev.ThrottleDevice {
878869 {
879- Path : dummyDev1 ,
870+ Path : lo . Device ,
880871 Rate : 1048576 , // 1MB/s
881872 },
882873 }
883874
884875 writeBpsDevices := []* blkiodev.ThrottleDevice {
885876 {
886- Path : dummyDev1 ,
877+ Path : lo . Device ,
887878 Rate : 2097152 , // 2MB/s
888879 },
889880 }
890881
891882 readIopsDevices := []* blkiodev.ThrottleDevice {
892883 {
893- Path : dummyDev1 ,
884+ Path : lo . Device ,
894885 Rate : 1000 ,
895886 },
896887 }
897888
898889 writeIopsDevices := []* blkiodev.ThrottleDevice {
899890 {
900- Path : dummyDev1 ,
891+ Path : lo . Device ,
901892 Rate : 2000 ,
902893 },
903894 }
@@ -920,93 +911,23 @@ func ContainerCreate(opt *option.Option, pOpt util.NewOpt) {
920911 // inspect container
921912 resp := command .Stdout (opt , "inspect" , testContainerName )
922913 var inspect []* dockercompat.Container
923- err : = json .Unmarshal (resp , & inspect )
914+ err = json .Unmarshal (resp , & inspect )
924915 Expect (err ).Should (BeNil ())
925916 Expect (inspect ).Should (HaveLen (1 ))
926917
927918 // Verify blkio settings in LinuxBlkioSettings
928- blkioSettings := inspect [0 ].HostConfig .LinuxBlkioSettings
919+ blkioSettings := inspect [0 ].HostConfig .BlkioSettings
929920 // Verify BlkioWeight
930921 Expect (blkioSettings .BlkioWeight ).Should (Equal (options .HostConfig .BlkioWeight ))
931922
932- // Helper function to map major/minor to device path
933- devicePathFromMajorMinor := func (major , minor int64 ) string {
934- if major == 1 && minor == 5 {
935- return dummyDev1
936- }
937- if major == 1 && minor == 6 {
938- return dummyDev2
939- }
940- return fmt .Sprintf ("/dev/unknown-%d-%d" , major , minor )
941- }
942-
943- // Helper function to convert specs.LinuxWeightDevice to blkiodev.WeightDevice
944- convertWeightDevice := func (wd * specs.LinuxWeightDevice ) * blkiodev.WeightDevice {
945- if wd == nil || wd .Weight == nil {
946- return nil
947- }
948- return & blkiodev.WeightDevice {
949- Path : devicePathFromMajorMinor (wd .Major , wd .Minor ),
950- Weight : * wd .Weight ,
951- }
952- }
953-
954- // Helper function to convert specs.LinuxThrottleDevice to blkiodev.ThrottleDevice
955- convertThrottleDevice := func (td * specs.LinuxThrottleDevice ) * blkiodev.ThrottleDevice {
956- if td == nil {
957- return nil
958- }
959- return & blkiodev.ThrottleDevice {
960- Path : devicePathFromMajorMinor (td .Major , td .Minor ),
961- Rate : td .Rate ,
962- }
963- }
964-
965- // Convert response devices to blkiodev types
966- responseWeightDevices := make ([]* blkiodev.WeightDevice , 0 , len (blkioSettings .BlkioWeightDevice ))
967- for _ , d := range blkioSettings .BlkioWeightDevice {
968- if converted := convertWeightDevice (d ); converted != nil {
969- responseWeightDevices = append (responseWeightDevices , converted )
970- }
971- }
972-
973- responseReadBpsDevices := make ([]* blkiodev.ThrottleDevice , 0 , len (blkioSettings .BlkioDeviceReadBps ))
974- for _ , d := range blkioSettings .BlkioDeviceReadBps {
975- if converted := convertThrottleDevice (d ); converted != nil {
976- responseReadBpsDevices = append (responseReadBpsDevices , converted )
977- }
978- }
979-
980- responseWriteBpsDevices := make ([]* blkiodev.ThrottleDevice , 0 , len (blkioSettings .BlkioDeviceWriteBps ))
981- for _ , d := range blkioSettings .BlkioDeviceWriteBps {
982- if converted := convertThrottleDevice (d ); converted != nil {
983- responseWriteBpsDevices = append (responseWriteBpsDevices , converted )
984- }
985- }
986-
987- responseReadIopsDevices := make ([]* blkiodev.ThrottleDevice , 0 , len (blkioSettings .BlkioDeviceReadIOps ))
988- for _ , d := range blkioSettings .BlkioDeviceReadIOps {
989- if converted := convertThrottleDevice (d ); converted != nil {
990- responseReadIopsDevices = append (responseReadIopsDevices , converted )
991- }
992- }
993-
994- responseWriteIopsDevices := make ([]* blkiodev.ThrottleDevice , 0 , len (blkioSettings .BlkioDeviceWriteIOps ))
995- for _ , d := range blkioSettings .BlkioDeviceWriteIOps {
996- if converted := convertThrottleDevice (d ); converted != nil {
997- responseWriteIopsDevices = append (responseWriteIopsDevices , converted )
998- }
999- }
1000-
1001923 // Compare string representations
1002924 for i , wd := range weightDevices {
1003- Expect (responseWeightDevices [i ].String ()).Should (Equal (wd .String ()))
925+ Expect (blkioSettings . BlkioWeightDevice [i ].String ()).Should (Equal (wd .String ()))
1004926 }
1005-
1006- Expect (responseReadBpsDevices [0 ].String ()).Should (Equal (readBpsDevices [0 ].String ()))
1007- Expect (responseWriteBpsDevices [0 ].String ()).Should (Equal (writeBpsDevices [0 ].String ()))
1008- Expect (responseReadIopsDevices [0 ].String ()).Should (Equal (readIopsDevices [0 ].String ()))
1009- Expect (responseWriteIopsDevices [0 ].String ()).Should (Equal (writeIopsDevices [0 ].String ()))
927+ Expect (blkioSettings .BlkioDeviceReadBps [0 ].String ()).Should (Equal (readBpsDevices [0 ].String ()))
928+ Expect (blkioSettings .BlkioDeviceWriteBps [0 ].String ()).Should (Equal (writeBpsDevices [0 ].String ()))
929+ Expect (blkioSettings .BlkioDeviceReadIOps [0 ].String ()).Should (Equal (readIopsDevices [0 ].String ()))
930+ Expect (blkioSettings .BlkioDeviceWriteIOps [0 ].String ()).Should (Equal (writeIopsDevices [0 ].String ()))
1010931 })
1011932
1012933 It ("should create container with volumes from another container" , func () {
0 commit comments