Signed-off-by: dattatrayakumbhar04 <dattatraya.kumbhar@gslab.com>
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"os" |
| 11 | 11 |
"path/filepath" |
| 12 | 12 |
"reflect" |
| 13 |
+ "strings" |
|
| 13 | 14 |
"sync" |
| 14 | 15 |
|
| 15 | 16 |
"github.com/pkg/errors" |
| ... | ... |
@@ -349,3 +350,15 @@ func validateOpts(opts map[string]string) error {
|
| 349 | 349 |
func (v *localVolume) Status() map[string]interface{} {
|
| 350 | 350 |
return nil |
| 351 | 351 |
} |
| 352 |
+ |
|
| 353 |
+// getAddress finds out address/hostname from options |
|
| 354 |
+func getAddress(opts string) string {
|
|
| 355 |
+ optsList := strings.Split(opts, ",") |
|
| 356 |
+ for i := 0; i < len(optsList); i++ {
|
|
| 357 |
+ if strings.HasPrefix(optsList[i], "addr=") {
|
|
| 358 |
+ addr := (strings.SplitN(optsList[i], "=", 2)[1]) |
|
| 359 |
+ return addr |
|
| 360 |
+ } |
|
| 361 |
+ } |
|
| 362 |
+ return "" |
|
| 363 |
+} |
| ... | ... |
@@ -12,6 +12,22 @@ import ( |
| 12 | 12 |
"github.com/docker/docker/pkg/mount" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 |
+func TestGetAddress(t *testing.T) {
|
|
| 16 |
+ cases := map[string]string{
|
|
| 17 |
+ "addr=11.11.11.1": "11.11.11.1", |
|
| 18 |
+ " ": "", |
|
| 19 |
+ "addr=": "", |
|
| 20 |
+ "addr=2001:db8::68": "2001:db8::68", |
|
| 21 |
+ } |
|
| 22 |
+ for name, success := range cases {
|
|
| 23 |
+ v := getAddress(name) |
|
| 24 |
+ if v != success {
|
|
| 25 |
+ t.Errorf("Test case failed for %s actual: %s expected : %s", name, v, success)
|
|
| 26 |
+ } |
|
| 27 |
+ } |
|
| 28 |
+ |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 15 | 31 |
func TestRemove(t *testing.T) {
|
| 16 | 32 |
// TODO Windows: Investigate why this test fails on Windows under CI |
| 17 | 33 |
// but passes locally. |
| ... | ... |
@@ -7,6 +7,7 @@ package local |
| 7 | 7 |
|
| 8 | 8 |
import ( |
| 9 | 9 |
"fmt" |
| 10 |
+ "net" |
|
| 10 | 11 |
"path/filepath" |
| 11 | 12 |
"strings" |
| 12 | 13 |
|
| ... | ... |
@@ -71,6 +72,16 @@ func (v *localVolume) mount() error {
|
| 71 | 71 |
if v.opts.MountDevice == "" {
|
| 72 | 72 |
return fmt.Errorf("missing device in volume options")
|
| 73 | 73 |
} |
| 74 |
- err := mount.Mount(v.opts.MountDevice, v.path, v.opts.MountType, v.opts.MountOpts) |
|
| 74 |
+ mountOpts := v.opts.MountOpts |
|
| 75 |
+ if v.opts.MountType == "nfs" {
|
|
| 76 |
+ if addrValue := getAddress(v.opts.MountOpts); addrValue != "" && net.ParseIP(addrValue).To4() == nil {
|
|
| 77 |
+ ipAddr, err := net.ResolveIPAddr("ip", addrValue)
|
|
| 78 |
+ if err != nil {
|
|
| 79 |
+ return errors.Wrapf(err, "error resolving passed in nfs address") |
|
| 80 |
+ } |
|
| 81 |
+ mountOpts = strings.Replace(mountOpts, "addr="+addrValue, "addr="+ipAddr.String(), 1) |
|
| 82 |
+ } |
|
| 83 |
+ } |
|
| 84 |
+ err := mount.Mount(v.opts.MountDevice, v.path, v.opts.MountType, mountOpts) |
|
| 75 | 85 |
return errors.Wrapf(err, "error while mounting volume with options: %s", v.opts) |
| 76 | 86 |
} |