From df6af282b9048dfedcd7b7a9a89126aca887f4e1 Mon Sep 17 00:00:00 2001 From: Amr Gawish Date: Mon, 26 Feb 2018 02:10:46 +0000 Subject: [PATCH] Print which path failed when the mount source doesn't exist. Changes Details: -------------- Fixes: #36395 Refactoring the code to do the following: 1. Add the method `errBindSourceDoesNotExist` inside `validate.go` to be in-line with the rest of error message 2. Utilised the new method inside `linux_parser.go`, `windows_parser.go` and `validate_test.go` 3. Change the format from `bind mount source path: '%s' does not exist` to `bind mount source path does not exist: %s` 4. Reflected the format change into the 2 unit tests, namely: `volume_test.go` and `validate_test.go` 5. Reflected the format change into `docker_api_containers_test.go` integration test Signed-off-by: Amr Gawish --- integration-cli/docker_api_containers_test.go | 2 +- volume/linux_parser.go | 2 +- volume/validate.go | 6 ++++-- volume/validate_test.go | 4 ++-- volume/volume_test.go | 4 ++-- volume/windows_parser.go | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index a91c91abe5..ed1941022e 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -1713,7 +1713,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *check.C) { Type: "bind", Source: notExistPath, Target: destPath}}}, - msg: "bind source path does not exist", + msg: "bind mount source path does not exist: " + notExistPath, }, { config: containertypes.Config{ diff --git a/volume/linux_parser.go b/volume/linux_parser.go index 3d94b789a0..6eb796b678 100644 --- a/volume/linux_parser.go +++ b/volume/linux_parser.go @@ -83,7 +83,7 @@ func (p *linuxParser) validateMountConfigImpl(mnt *mount.Mount, validateBindSour if validateBindSourceExists { exists, _, _ := currentFileInfoProvider.fileInfo(mnt.Source) if !exists { - return &errMountConfig{mnt, errBindNotExist} + return &errMountConfig{mnt, errBindSourceDoesNotExist(mnt.Source)} } } diff --git a/volume/validate.go b/volume/validate.go index 3ebdcd7d98..6512fb11ba 100644 --- a/volume/validate.go +++ b/volume/validate.go @@ -7,8 +7,6 @@ import ( "github.com/pkg/errors" ) -var errBindNotExist = errors.New("bind source path does not exist") - type errMountConfig struct { mount *mount.Mount err error @@ -18,6 +16,10 @@ func (e *errMountConfig) Error() string { return fmt.Sprintf("invalid mount config for type %q: %v", e.mount.Type, e.err.Error()) } +func errBindSourceDoesNotExist(path string) error { + return errors.Errorf("bind mount source path does not exist: %s", path) +} + func errExtraField(name string) error { return errors.Errorf("field %s must not be specified", name) } diff --git a/volume/validate_test.go b/volume/validate_test.go index d767b3d7f3..d230ef3193 100644 --- a/volume/validate_test.go +++ b/volume/validate_test.go @@ -31,7 +31,7 @@ func TestValidateMount(t *testing.T) { {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: testDestinationPath}, nil}, {mount.Mount{Type: "invalid", Target: testDestinationPath}, errors.New("mount type unknown")}, - {mount.Mount{Type: mount.TypeBind, Source: testSourcePath, Target: testDestinationPath}, errBindNotExist}, + {mount.Mount{Type: mount.TypeBind, Source: testSourcePath, Target: testDestinationPath}, errBindSourceDoesNotExist(testSourcePath)}, } lcowCases := []struct { @@ -44,7 +44,7 @@ func TestValidateMount(t *testing.T) { {mount.Mount{Type: mount.TypeBind}, errMissingField("Target")}, {mount.Mount{Type: mount.TypeBind, Target: "/foo"}, errMissingField("Source")}, {mount.Mount{Type: mount.TypeBind, Target: "/foo", Source: "c:\\foo", VolumeOptions: &mount.VolumeOptions{}}, errExtraField("VolumeOptions")}, - {mount.Mount{Type: mount.TypeBind, Source: "c:\\foo", Target: "/foo"}, errBindNotExist}, + {mount.Mount{Type: mount.TypeBind, Source: "c:\\foo", Target: "/foo"}, errBindSourceDoesNotExist("c:\\foo")}, {mount.Mount{Type: mount.TypeBind, Source: testDir, Target: "/foo"}, nil}, {mount.Mount{Type: "invalid", Target: "/foo"}, errors.New("mount type unknown")}, } diff --git a/volume/volume_test.go b/volume/volume_test.go index 3ff2861bab..f5bc1b0f54 100644 --- a/volume/volume_test.go +++ b/volume/volume_test.go @@ -120,7 +120,7 @@ func TestParseMountRaw(t *testing.T) { `c:\:d:\:xyzzy`: "invalid volume specification: ", `c:`: "cannot be `c:`", `c:\`: "cannot be `c:`", - `c:\notexist:d:`: `source path does not exist`, + `c:\notexist:d:`: `bind mount source path does not exist: c:\notexist`, `c:\windows\system32\ntdll.dll:d:`: `source path must be a directory`, `name<:d:`: `invalid volume specification`, `name>:d:`: `invalid volume specification`, @@ -189,7 +189,7 @@ func TestParseMountRaw(t *testing.T) { `c:\:/foo:xyzzy`: "invalid volume specification: ", `/`: "destination can't be '/'", `/..`: "destination can't be '/'", - `c:\notexist:/foo`: `source path does not exist`, + `c:\notexist:/foo`: `bind mount source path does not exist: c:\notexist`, `c:\windows\system32\ntdll.dll:/foo`: `source path must be a directory`, `name<:/foo`: `invalid volume specification`, `name>:/foo`: `invalid volume specification`, diff --git a/volume/windows_parser.go b/volume/windows_parser.go index ad4e6fc281..84b6717c95 100644 --- a/volume/windows_parser.go +++ b/volume/windows_parser.go @@ -252,7 +252,7 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, destRegex strin return &errMountConfig{mnt, err} } if !exists { - return &errMountConfig{mnt, errBindNotExist} + return &errMountConfig{mnt, errBindSourceDoesNotExist(mnt.Source)} } if !isdir { return &errMountConfig{mnt, fmt.Errorf("source path must be a directory")}