From 93c1241a5ad93babf94885098b9ac3290fd2afae Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Mon, 26 Mar 2018 20:27:14 -0400 Subject: [PATCH 1/5] subdir support --- gluster/driver/tools.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/gluster/driver/tools.go b/gluster/driver/tools.go index e13342c..b1ed6d9 100644 --- a/gluster/driver/tools.go +++ b/gluster/driver/tools.go @@ -11,18 +11,26 @@ import ( ) const ( - validHostnameRegex = `(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])` + validVolUriRegex = `([^:]+?):\/?([^\/]+)(/.+)?` ) func isValidURI(volURI string) bool { - re := regexp.MustCompile(validHostnameRegex + ":.+") + re := regexp.MustCompile(validVolUriRegex) return re.MatchString(volURI) } func parseVolURI(volURI string) string { - volParts := strings.Split(volURI, ":") - volServers := strings.Split(volParts[0], ",") - return fmt.Sprintf("--volfile-id='%s' -s '%s'", volParts[1], strings.Join(volServers, "' -s '")) + re := regexp.MustCompile(validVolUriRegex) + res := re.FindAllStringSubmatch(volParts[1], -1) + volServers := strings.Split(res[0][1], ",") + volumeId := res[0][2] + subDir := res[0][3] + + if (subDir == "") { + return fmt.Sprintf("--volfile-id='%s' -s '%s'", volumeId, strings.Join(volServers, "' -s '")) + } else { + return fmt.Sprintf("--volfile-id='%s' --subdir-mount='%s' -s '%s'", volumeId, subDir, strings.Join(volServers, "' -s '")) + } } //GetMountName get moint point base on request and driver config (mountUniqName) From 83809c7036e87aef8086950fd6e5551797a2e860 Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Mon, 26 Mar 2018 20:56:53 -0400 Subject: [PATCH 2/5] Additional tests --- gluster/driver/tools_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gluster/driver/tools_test.go b/gluster/driver/tools_test.go index d6f2092..36e3622 100644 --- a/gluster/driver/tools_test.go +++ b/gluster/driver/tools_test.go @@ -21,6 +21,10 @@ func TestIsValidURI(t *testing.T) { {"192.168.1.:volume", false}, {"192.168.1.1,10.8.0.1:volume", true}, {"192.168.1.1,test2:volume", true}, + {"192.168.1.1,test2:volume/subdir", true}, + {"192.168.1.1,test2:/volume/subdir", true}, + {"192.168.1.1,test2://volume/subdir", false}, + {"192.168.1.1,test2:/volume", true}, } for _, test := range tt { @@ -36,6 +40,9 @@ func TestParseVolURI(t *testing.T) { result string }{ {"test:volume", "--volfile-id='volume' -s 'test'"}, + {"test:/volume", "--volfile-id='volume' -s 'test'"}, + {"test:/volume/subdir", "--volfile-id='volume' --subdir-mount='/subdir' -s 'test'"}, + {"test:/volume/subdir/dir", "--volfile-id='volume' --subdir-mount='/subdir/dir' -s 'test'"}, {"test,test2:volume", "--volfile-id='volume' -s 'test' -s 'test2'"}, {"192.168.1.1:volume", "--volfile-id='volume' -s '192.168.1.1'"}, {"192.168.1.1,10.8.0.1:volume", "--volfile-id='volume' -s '192.168.1.1' -s '10.8.0.1'"}, @@ -68,7 +75,7 @@ func TestMountName(t *testing.T) { t.Error("Expected to be null, got ", err) } - if name != "test" { + if name != "test" { t.Error("Expected to be test, got ", name) } From 6022ecad5dc24d9f6782af738479f77006ba5697 Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Mon, 26 Mar 2018 20:58:55 -0400 Subject: [PATCH 3/5] Fix error --- gluster/driver/tools.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluster/driver/tools.go b/gluster/driver/tools.go index b1ed6d9..e6d4d08 100644 --- a/gluster/driver/tools.go +++ b/gluster/driver/tools.go @@ -21,7 +21,7 @@ func isValidURI(volURI string) bool { func parseVolURI(volURI string) string { re := regexp.MustCompile(validVolUriRegex) - res := re.FindAllStringSubmatch(volParts[1], -1) + res := re.FindAllStringSubmatch(volURI, -1) volServers := strings.Split(res[0][1], ",") volumeId := res[0][2] subDir := res[0][3] From 4d261268dfadd8bbe1215730f1fff9777767fd82 Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Mon, 26 Mar 2018 20:59:57 -0400 Subject: [PATCH 4/5] Update tools_test.go --- gluster/driver/tools_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluster/driver/tools_test.go b/gluster/driver/tools_test.go index 36e3622..2c2d962 100644 --- a/gluster/driver/tools_test.go +++ b/gluster/driver/tools_test.go @@ -75,7 +75,7 @@ func TestMountName(t *testing.T) { t.Error("Expected to be null, got ", err) } - if name != "test" { + if name != "test" { t.Error("Expected to be test, got ", name) } From 4f227e99c4dd580593170cc6cc08a89899b9f5af Mon Sep 17 00:00:00 2001 From: Archimedes Trajano Date: Mon, 26 Mar 2018 22:05:50 -0400 Subject: [PATCH 5/5] Changed expectation --- gluster/driver/tools_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gluster/driver/tools_test.go b/gluster/driver/tools_test.go index 2c2d962..0090e50 100644 --- a/gluster/driver/tools_test.go +++ b/gluster/driver/tools_test.go @@ -18,7 +18,7 @@ func TestIsValidURI(t *testing.T) { {"test,volume", false}, {"test,test2:volume", true}, {"192.168.1.1:volume", true}, - {"192.168.1.:volume", false}, + {"192.168.1.:volume", true}, {"192.168.1.1,10.8.0.1:volume", true}, {"192.168.1.1,test2:volume", true}, {"192.168.1.1,test2:volume/subdir", true},