@@ -4,11 +4,13 @@ import (
44 "encoding/json"
55 "fmt"
66 "io/ioutil"
7+ "strconv"
78 "strings"
89
910 "github.com/alibaba/pouch/apis/types"
1011 "github.com/alibaba/pouch/test/command"
1112 "github.com/alibaba/pouch/test/environment"
13+ "github.com/alibaba/pouch/test/util"
1214
1315 "github.com/go-check/check"
1416 "github.com/gotestyourself/gotestyourself/icmd"
@@ -37,8 +39,9 @@ func (suite *PouchRunBlkioSuite) TearDownTest(c *check.C) {
3739// TestRunBlockIOWeight tests running container with --blkio-weight flag.
3840func (suite * PouchRunBlkioSuite ) TestRunBlockIOWeight (c * check.C ) {
3941 cname := "TestRunBlockIOWeight"
42+ strvalue := "100"
4043
41- res := command .PouchRun ("run" , "-d" , "--blkio-weight" , "100" ,
44+ res := command .PouchRun ("run" , "-d" , "--blkio-weight" , strvalue ,
4245 "--name" , cname , busyboxImage , "sleep" , "10000" )
4346 defer DelContainerForceMultyTime (c , cname )
4447 res .Assert (c , icmd .Success )
@@ -52,19 +55,29 @@ func (suite *PouchRunBlkioSuite) TestRunBlockIOWeight(c *check.C) {
5255 c .Errorf ("failed to decode inspect output: %v" , err )
5356 }
5457
55- c .Assert (result [0 ].HostConfig .BlkioWeight , check .Equals , uint16 (100 ))
58+ value , _ := strconv .Atoi (strvalue )
59+ c .Assert (result [0 ].HostConfig .BlkioWeight , check .Equals , uint16 (value ))
5660
5761 // test if cgroup has record the real value
5862 containerID := result [0 ].ID
5963 path := fmt .Sprintf (
6064 "/sys/fs/cgroup/blkio/default/%s/blkio.weight" , containerID )
61- checkFileContains (c , path , "100" )
65+ checkFileContains (c , path , strvalue )
66+
67+ // test if the value is correct in container
68+ blkioWeightFile := "/sys/fs/cgroup/blkio/blkio.weight"
69+ res = command .PouchRun ("exec" , cname , "cat" , blkioWeightFile )
70+ res .Assert (c , icmd .Success )
71+
72+ out := res .Stdout ()
73+ c .Assert (out , check .Equals , strvalue + "\n " )
6274}
6375
6476// TestRunBlockIOWeightDevice tests running container
6577// with --blkio-weight-device flag.
6678func (suite * PouchRunBlkioSuite ) TestRunBlockIOWeightDevice (c * check.C ) {
6779 cname := "TestRunBlockIOWeightDevice"
80+ value := 100
6881 testDisk , found := environment .FindDisk ()
6982 if ! found {
7083 c .Skip ("fail to find available disk for blkio test" )
@@ -80,7 +93,7 @@ func (suite *PouchRunBlkioSuite) TestRunBlockIOWeightDevice(c *check.C) {
8093 })
8194
8295 res := command .PouchRun ("run" , "-d" ,
83- "--blkio-weight-device" , testDisk + ":100" ,
96+ "--blkio-weight-device" , testDisk + ":" + strconv . Itoa ( value ) ,
8497 "--name" , cname , busyboxImage , "sleep" , "10000" )
8598 defer DelContainerForceMultyTime (c , cname )
8699 res .Assert (c , icmd .Success )
@@ -98,7 +111,28 @@ func (suite *PouchRunBlkioSuite) TestRunBlockIOWeightDevice(c *check.C) {
98111 c .Assert (result [0 ].HostConfig .BlkioWeightDevice [0 ].Path ,
99112 check .Equals , testDisk )
100113 c .Assert (result [0 ].HostConfig .BlkioWeightDevice [0 ].Weight ,
101- check .Equals , uint16 (100 ))
114+ check .Equals , uint16 (value ))
115+
116+ number , exist := util .getMajMinNumOfDevice (testDisk )
117+ if ! exist {
118+ c .Skip ("fail to get major:minor device number" )
119+ }
120+
121+ expected := fmt .Sprintf ("%s %d\n " , number , value )
122+
123+ // test if the value is correct on the host
124+ containerID := result [0 ].ID
125+ path := fmt .Sprintf (
126+ "/sys/fs/cgroup/blkio/default/%s/blkio.weight_device" , containerID )
127+ checkFileContains (c , path , strings .Trim (expected , "\n " ))
128+
129+ // test if the value is correct in container
130+ blkioWeightDevFile := "/sys/fs/cgroup/blkio/blkio.weight_device"
131+ res = command .PouchRun ("exec" , cname , "cat" , blkioWeightDevFile )
132+ res .Assert (c , icmd .Success )
133+
134+ out := res .Stdout ()
135+ c .Assert (out , check .Equals , expected )
102136}
103137
104138// TestRunWithBlkioWeight is to verify --specific Blkio Weight
0 commit comments