Skip to content

Commit

Permalink
Fix array identification with DNS (#112)
Browse files Browse the repository at this point in the history
* Add condition to check for array dns

* fix UT
  • Loading branch information
panigs7 authored Jan 3, 2025
1 parent 380c30f commit 9d8cb07
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
18 changes: 14 additions & 4 deletions internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"path/filepath"
"regexp"
"strconv"
"strings"

csictx "github.com/dell/gocsi/context"

Expand Down Expand Up @@ -101,13 +102,22 @@ func GetPowerStoreArrays(filePath string, logger *logrus.Logger) (map[string]*se
"unable to create PowerStore client: %s", err.Error())
}
array.Client = c

var ip string
ips := GetIPListFromString(array.Endpoint)
if ips == nil {
return nil, nil, nil, fmt.Errorf("can't get ips from endpoint: %s", array.Endpoint)
logger.Warnf("didn't found an IP from the provided endPoint, it could be a FQDN. Please make sure to enter a valid FQDN in https://abc.com/api/rest format")
sub := strings.Split(array.Endpoint, "/")
if len(sub) > 2 {
ip = sub[2]
if regexp.MustCompile(`^[0-9.]*$`).MatchString(sub[2]) {
return nil, nil, nil, fmt.Errorf("can't get ips from endpoint: %s", array.Endpoint)
}
} else {
return nil, nil, nil, fmt.Errorf("can't get ips from endpoint: %s", array.Endpoint)
}
} else {
ip = ips[0]
}

ip := ips[0]
array.IP = ip
logger.Infof("%s,%s,%s,%s,%t,%t,%s", array.Endpoint, array.GlobalID, array.Username, array.NasName, array.Insecure, array.IsDefault, array.BlockProtocol)
arrayMap[array.GlobalID] = array
Expand Down
4 changes: 2 additions & 2 deletions internal/common/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func Test_Run(t *testing.T) {
"nil array entry": func(*testing.T) (string, map[string]string, bool) {
return "testdata/nil-array.yaml", nil, true
},
"invalid client creation": func(*testing.T) (string, map[string]string, bool) {
return "testdata/invalid-client.yaml", nil, true
"client with dns creation": func(*testing.T) (string, map[string]string, bool) {
return "testdata/client-dns.yaml", nil, false
},
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
arrays:
- endpoint: "https://invalid_endpoint"
- endpoint: "https://dns_endpoint/api/rest"
globalID: "array1"
username: "user"
password: "password"
Expand Down

0 comments on commit 9d8cb07

Please sign in to comment.