mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
runconfig: return correct error-types and touch-up error messages
Make sure we return a proper errdefs.InvalidParameter for these, and update some error-messages to fix linting issues. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/strslice"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/sysinfo"
|
||||
"gotest.tools/v3/assert"
|
||||
is "gotest.tools/v3/assert/cmp"
|
||||
@@ -73,17 +74,17 @@ func TestDecodeContainerConfigIsolation(t *testing.T) {
|
||||
{
|
||||
isolation: "invalid",
|
||||
invalid: true,
|
||||
expectedErr: `Invalid isolation: "invalid"`,
|
||||
expectedErr: `invalid isolation (invalid):`,
|
||||
},
|
||||
{
|
||||
isolation: "process",
|
||||
invalid: runtime.GOOS != "windows",
|
||||
expectedErr: `Invalid isolation: "process"`,
|
||||
expectedErr: `invalid isolation (process):`,
|
||||
},
|
||||
{
|
||||
isolation: "hyperv",
|
||||
invalid: runtime.GOOS != "windows",
|
||||
expectedErr: `Invalid isolation: "hyperv"`,
|
||||
expectedErr: `invalid isolation (hyperv):`,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
@@ -99,6 +100,7 @@ func TestDecodeContainerConfigIsolation(t *testing.T) {
|
||||
_, _, _, err = decodeContainerConfig(bytes.NewReader(b), sysinfo.New())
|
||||
if tc.invalid {
|
||||
assert.Check(t, is.ErrorContains(err, tc.expectedErr))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
@@ -112,8 +114,9 @@ func TestDecodeContainerConfigPrivileged(t *testing.T) {
|
||||
|
||||
_, _, _, err = decodeContainerConfig(bytes.NewReader(requestJSON), sysinfo.New())
|
||||
if runtime.GOOS == "windows" {
|
||||
const expected = "Windows does not support privileged mode"
|
||||
const expected = "invalid option: privileged mode is not supported for Windows containers"
|
||||
assert.Check(t, is.Error(err, expected))
|
||||
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ func validateNetContainerMode(c *container.Config, hc *container.HostConfig) err
|
||||
}
|
||||
|
||||
if hc.NetworkMode.ConnectedContainer() == "" {
|
||||
return validationError("Invalid network mode: invalid container format container:<name|id>")
|
||||
return validationError("invalid network mode: invalid container format container:<name|id>")
|
||||
}
|
||||
|
||||
if c.Hostname != "" {
|
||||
|
||||
@@ -31,7 +31,7 @@ func validateNetMode(c *container.Config, hc *container.HostConfig) error {
|
||||
// which is LXC container isolation
|
||||
func validateIsolation(hc *container.HostConfig) error {
|
||||
if !hc.Isolation.IsValid() {
|
||||
return fmt.Errorf("Invalid isolation: %q - %s only supports 'default'", hc.Isolation, runtime.GOOS)
|
||||
return validationError(fmt.Sprintf("invalid isolation (%s): %s only supports 'default'", hc.Isolation, runtime.GOOS))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -39,10 +39,10 @@ func validateIsolation(hc *container.HostConfig) error {
|
||||
// validateQoS performs platform specific validation of the QoS settings
|
||||
func validateQoS(hc *container.HostConfig) error {
|
||||
if hc.IOMaximumBandwidth != 0 {
|
||||
return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum bandwidth", runtime.GOOS)
|
||||
return validationError(fmt.Sprintf("invalid option: QoS maximum bandwidth configuration is not supported on %s", runtime.GOOS))
|
||||
}
|
||||
if hc.IOMaximumIOps != 0 {
|
||||
return fmt.Errorf("Invalid QoS settings: %s does not support configuration of maximum IOPs", runtime.GOOS)
|
||||
return validationError(fmt.Sprintf("invalid option: QoS maximum IOPs configuration is not supported on %s", runtime.GOOS))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -51,10 +51,10 @@ func validateQoS(hc *container.HostConfig) error {
|
||||
// cpu-rt-runtime and cpu-rt-period can not be greater than their parent, cpu-rt-runtime requires sys_nice
|
||||
func validateResources(hc *container.HostConfig, si *sysinfo.SysInfo) error {
|
||||
if (hc.Resources.CPURealtimePeriod != 0 || hc.Resources.CPURealtimeRuntime != 0) && !si.CPURealtime {
|
||||
return fmt.Errorf("Your kernel does not support CPU real-time scheduler")
|
||||
return validationError("kernel does not support CPU real-time scheduler")
|
||||
}
|
||||
if hc.Resources.CPURealtimePeriod != 0 && hc.Resources.CPURealtimeRuntime != 0 && hc.Resources.CPURealtimeRuntime > hc.Resources.CPURealtimePeriod {
|
||||
return fmt.Errorf("cpu real-time runtime cannot be higher than cpu real-time period")
|
||||
return validationError("cpu real-time runtime cannot be higher than cpu real-time period")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ func validateNetMode(c *container.Config, hc *container.HostConfig) error {
|
||||
return err
|
||||
}
|
||||
if hc.NetworkMode.IsContainer() && hc.Isolation.IsHyperV() {
|
||||
return fmt.Errorf("Using the network stack of another container is not supported while using Hyper-V Containers")
|
||||
return validationError("invalid network-mode: using the network stack of another container is not supported while using Hyper-V Containers")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func validateNetMode(c *container.Config, hc *container.HostConfig) error {
|
||||
// blank), 'process', or 'hyperv'.
|
||||
func validateIsolation(hc *container.HostConfig) error {
|
||||
if !hc.Isolation.IsValid() {
|
||||
return fmt.Errorf("Invalid isolation: %q. Windows supports 'default', 'process', or 'hyperv'", hc.Isolation)
|
||||
return validationError(fmt.Sprintf("invalid isolation (%s): Windows supports 'default', 'process', or 'hyperv'", hc.Isolation))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -37,10 +37,10 @@ func validateQoS(_ *container.HostConfig) error {
|
||||
// validateResources performs platform specific validation of the resource settings
|
||||
func validateResources(hc *container.HostConfig, _ *sysinfo.SysInfo) error {
|
||||
if hc.Resources.CPURealtimePeriod != 0 {
|
||||
return fmt.Errorf("Windows does not support CPU real-time period")
|
||||
return validationError("invalid option: CPU real-time period is not supported for Windows containers")
|
||||
}
|
||||
if hc.Resources.CPURealtimeRuntime != 0 {
|
||||
return fmt.Errorf("Windows does not support CPU real-time runtime")
|
||||
return validationError("invalid option: CPU real-time runtime is not supported for Windows containers")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func validateResources(hc *container.HostConfig, _ *sysinfo.SysInfo) error {
|
||||
// validatePrivileged performs platform specific validation of the Privileged setting
|
||||
func validatePrivileged(hc *container.HostConfig) error {
|
||||
if hc.Privileged {
|
||||
return fmt.Errorf("Windows does not support privileged mode")
|
||||
return validationError("invalid option: privileged mode is not supported for Windows containers")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func validatePrivileged(hc *container.HostConfig) error {
|
||||
// validateReadonlyRootfs performs platform specific validation of the ReadonlyRootfs setting
|
||||
func validateReadonlyRootfs(hc *container.HostConfig) error {
|
||||
if hc.ReadonlyRootfs {
|
||||
return fmt.Errorf("Windows does not support root filesystem in read-only mode")
|
||||
return validationError("invalid option: read-only mode is not supported for Windows containers")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user