@@ -432,6 +432,126 @@ func ContainerCreate(opt *option.Option) {
432432 // verify log path exists
433433 Expect (inspect [0 ].LogPath ).ShouldNot (BeNil ())
434434 })
435+
436+ It ("should create a container with specified CPU qouta and period options" , func () {
437+ // define options
438+ options .Cmd = []string {"sleep" , "Infinity" }
439+ options .HostConfig .CPUQuota = 11111
440+ options .HostConfig .CPUShares = 2048
441+ options .HostConfig .CPUPeriod = 100000
442+
443+ // create container
444+ statusCode , ctr := createContainer (uClient , url , testContainerName , options )
445+ Expect (statusCode ).Should (Equal (http .StatusCreated ))
446+ Expect (ctr .ID ).ShouldNot (BeEmpty ())
447+
448+ nativeResp := command .Stdout (opt , "inspect" , "--mode=native" , testContainerName )
449+ var nativeInspect []map [string ]interface {}
450+ err := json .Unmarshal ([]byte (nativeResp ), & nativeInspect )
451+ Expect (err ).Should (BeNil ())
452+ Expect (nativeInspect ).Should (HaveLen (1 ))
453+
454+ // Navigate to the CPU quota value
455+ spec , ok := nativeInspect [0 ]["Spec" ].(map [string ]interface {})
456+ Expect (ok ).Should (BeTrue ())
457+ linux , ok := spec ["linux" ].(map [string ]interface {})
458+ Expect (ok ).Should (BeTrue ())
459+ resources , ok := linux ["resources" ].(map [string ]interface {})
460+ Expect (ok ).Should (BeTrue ())
461+ cpu , ok := resources ["cpu" ].(map [string ]interface {})
462+ Expect (ok ).Should (BeTrue ())
463+ quota , ok := cpu ["quota" ].(float64 )
464+ Expect (ok ).Should (BeTrue ())
465+ period , ok := cpu ["period" ].(float64 )
466+ Expect (ok ).Should (BeTrue ())
467+ shares , ok := cpu ["shares" ].(float64 )
468+ Expect (ok ).Should (BeTrue ())
469+
470+ // Verify the CPU quota
471+ Expect (int64 (quota )).Should (Equal (int64 (11111 )))
472+ Expect (int64 (shares )).Should (Equal (int64 (2048 )))
473+ Expect (int64 (period )).Should (Equal (int64 (100000 )))
474+
475+ })
476+
477+ It ("should create a container with specified Memory qouta and PidLimits options" , func () {
478+ // define options
479+ options .Cmd = []string {"sleep" , "Infinity" }
480+ options .HostConfig .Memory = 4048
481+ options .HostConfig .PidsLimit = 200
482+ options .HostConfig .MemoryReservation = 28
483+ options .HostConfig .MemorySwap = 514288000
484+ options .HostConfig .MemorySwappiness = 25
485+
486+ // create container
487+ statusCode , ctr := createContainer (uClient , url , testContainerName , options )
488+ Expect (statusCode ).Should (Equal (http .StatusCreated ))
489+ Expect (ctr .ID ).ShouldNot (BeEmpty ())
490+
491+ nativeResp := command .Stdout (opt , "inspect" , "--mode=native" , testContainerName )
492+ var nativeInspect []map [string ]interface {}
493+ err := json .Unmarshal ([]byte (nativeResp ), & nativeInspect )
494+ Expect (err ).Should (BeNil ())
495+ Expect (nativeInspect ).Should (HaveLen (1 ))
496+
497+ // Navigate to the CPU quota value
498+ spec , ok := nativeInspect [0 ]["Spec" ].(map [string ]interface {})
499+ Expect (ok ).Should (BeTrue ())
500+ linux , ok := spec ["linux" ].(map [string ]interface {})
501+ Expect (ok ).Should (BeTrue ())
502+ resources , ok := linux ["resources" ].(map [string ]interface {})
503+ Expect (ok ).Should (BeTrue ())
504+ memory , _ := resources ["memory" ].(map [string ]interface {})
505+
506+ pids , _ := resources ["pids" ].(map [string ]interface {})
507+
508+ Expect (int64 (pids ["limit" ].(float64 ))).Should (Equal (options .HostConfig .PidsLimit ))
509+ Expect (int64 (memory ["limit" ].(float64 ))).Should (Equal (options .HostConfig .Memory ))
510+
511+ })
512+
513+ It ("should create a container with specified Ulimit options" , func () {
514+ // define options
515+ options .Cmd = []string {"sleep" , "Infinity" }
516+
517+ options .HostConfig .Ulimits = []* types.Ulimit {
518+ {
519+ Name : "nofile" ,
520+ Soft : 1024 ,
521+ Hard : 2048 ,
522+ },
523+ }
524+
525+ // create container
526+ statusCode , ctr := createContainer (uClient , url , testContainerName , options )
527+ Expect (statusCode ).Should (Equal (http .StatusCreated ))
528+ Expect (ctr .ID ).ShouldNot (BeEmpty ())
529+
530+ nativeResp := command .Stdout (opt , "inspect" , "--mode=native" , testContainerName )
531+ var nativeInspect []map [string ]interface {}
532+ err := json .Unmarshal ([]byte (nativeResp ), & nativeInspect )
533+ Expect (err ).Should (BeNil ())
534+ Expect (nativeInspect ).Should (HaveLen (1 ))
535+
536+ // Navigate to the CPU quota value
537+ spec , _ := nativeInspect [0 ]["Spec" ].(map [string ]interface {})
538+ rlimits := spec ["process" ].(map [string ]interface {})["rlimits" ].([]interface {})
539+ for _ , ulimit := range options .HostConfig .Ulimits {
540+ found := false
541+ for _ , rlimit := range rlimits {
542+ r := rlimit .(map [string ]interface {})
543+ if r ["type" ] == "RLIMIT_NOFILE" {
544+ Expect (r ["hard" ]).To (Equal (float64 (ulimit .Hard )))
545+ Expect (r ["soft" ]).To (Equal (float64 (ulimit .Soft )))
546+ found = true
547+ break
548+ }
549+ }
550+ Expect (found ).To (BeTrue ())
551+ }
552+
553+ })
554+
435555 It ("should create a container with specified network options" , func () {
436556 // define options
437557 options .Cmd = []string {"sleep" , "Infinity" }
0 commit comments