|
@@ -1,67 +1,86 @@
|
|
|
-// +build linux
|
|
|
+// +build !windows
|
|
|
|
|
|
-package server
|
|
|
+package daemon
|
|
|
|
|
|
import (
|
|
|
+ "io/ioutil"
|
|
|
+ "os"
|
|
|
"testing"
|
|
|
|
|
|
- "github.com/docker/docker/pkg/version"
|
|
|
"github.com/docker/docker/runconfig"
|
|
|
)
|
|
|
|
|
|
-func TestAdjustCPUSharesOldApi(t *testing.T) {
|
|
|
- apiVersion := version.Version("1.18")
|
|
|
+func TestAdjustCPUShares(t *testing.T) {
|
|
|
+ tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ defer os.RemoveAll(tmp)
|
|
|
+ daemon := &Daemon{
|
|
|
+ repository: tmp,
|
|
|
+ root: tmp,
|
|
|
+ }
|
|
|
+
|
|
|
hostConfig := &runconfig.HostConfig{
|
|
|
CPUShares: linuxMinCPUShares - 1,
|
|
|
}
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, true)
|
|
|
if hostConfig.CPUShares != linuxMinCPUShares {
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares)
|
|
|
}
|
|
|
|
|
|
hostConfig.CPUShares = linuxMaxCPUShares + 1
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, true)
|
|
|
if hostConfig.CPUShares != linuxMaxCPUShares {
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares)
|
|
|
}
|
|
|
|
|
|
hostConfig.CPUShares = 0
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, true)
|
|
|
if hostConfig.CPUShares != 0 {
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
|
|
}
|
|
|
|
|
|
hostConfig.CPUShares = 1024
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, true)
|
|
|
if hostConfig.CPUShares != 1024 {
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
|
|
- apiVersion := version.Version("1.19")
|
|
|
+ tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ defer os.RemoveAll(tmp)
|
|
|
+ daemon := &Daemon{
|
|
|
+ repository: tmp,
|
|
|
+ root: tmp,
|
|
|
+ }
|
|
|
+
|
|
|
hostConfig := &runconfig.HostConfig{
|
|
|
CPUShares: linuxMinCPUShares - 1,
|
|
|
}
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, false)
|
|
|
if hostConfig.CPUShares != linuxMinCPUShares-1 {
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMinCPUShares-1)
|
|
|
}
|
|
|
|
|
|
hostConfig.CPUShares = linuxMaxCPUShares + 1
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, false)
|
|
|
if hostConfig.CPUShares != linuxMaxCPUShares+1 {
|
|
|
t.Errorf("Expected CPUShares to be %d", linuxMaxCPUShares+1)
|
|
|
}
|
|
|
|
|
|
hostConfig.CPUShares = 0
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, false)
|
|
|
if hostConfig.CPUShares != 0 {
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
|
|
}
|
|
|
|
|
|
hostConfig.CPUShares = 1024
|
|
|
- adjustCPUShares(apiVersion, hostConfig)
|
|
|
+ daemon.adaptContainerSettings(hostConfig, false)
|
|
|
if hostConfig.CPUShares != 1024 {
|
|
|
t.Error("Expected CPUShares to be unchanged")
|
|
|
}
|