From 9d8cb0793b0188b8dd31d48de06c0478040d5529 Mon Sep 17 00:00:00 2001 From: panigs7 <92028646+panigs7@users.noreply.github.com> Date: Fri, 3 Jan 2025 18:02:38 +0530 Subject: [PATCH] Fix array identification with DNS (#112) * Add condition to check for array dns * fix UT --- internal/common/common.go | 18 ++++++++++++++---- internal/common/common_test.go | 4 ++-- .../{invalid-client.yaml => client-dns.yaml} | 2 +- 3 files changed, 17 insertions(+), 7 deletions(-) rename internal/common/testdata/{invalid-client.yaml => client-dns.yaml} (71%) diff --git a/internal/common/common.go b/internal/common/common.go index 88fb700..2e7528d 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -24,6 +24,7 @@ import ( "path/filepath" "regexp" "strconv" + "strings" csictx "github.com/dell/gocsi/context" @@ -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 diff --git a/internal/common/common_test.go b/internal/common/common_test.go index 0973a08..dba3b42 100644 --- a/internal/common/common_test.go +++ b/internal/common/common_test.go @@ -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 }, } diff --git a/internal/common/testdata/invalid-client.yaml b/internal/common/testdata/client-dns.yaml similarity index 71% rename from internal/common/testdata/invalid-client.yaml rename to internal/common/testdata/client-dns.yaml index 4b82dd3..5216c7a 100644 --- a/internal/common/testdata/invalid-client.yaml +++ b/internal/common/testdata/client-dns.yaml @@ -1,5 +1,5 @@ arrays: - - endpoint: "https://invalid_endpoint" + - endpoint: "https://dns_endpoint/api/rest" globalID: "array1" username: "user" password: "password"