Skip to content

Commit

Permalink
Update dependencies and remove dependency on csi-powerstore (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdawe authored Dec 10, 2021
1 parent f099b6a commit df88484
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 42 deletions.
7 changes: 2 additions & 5 deletions cmd/metrics-powerstore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ import (

_ "net/http/pprof"

"github.com/dell/csi-powerstore/pkg/array"
"github.com/dell/csi-powerstore/pkg/common/fs"
"github.com/dell/csm-metrics-powerstore/internal/common"
"github.com/dell/csm-metrics-powerstore/internal/entrypoint"
"github.com/dell/csm-metrics-powerstore/internal/k8s"
"github.com/dell/csm-metrics-powerstore/internal/service"
otlexporters "github.com/dell/csm-metrics-powerstore/opentelemetry/exporters"
tracer "github.com/dell/csm-metrics-powerstore/opentelemetry/tracers"
"github.com/dell/gofsutil"
"github.com/sirupsen/logrus"

"os"
Expand Down Expand Up @@ -197,8 +195,7 @@ func updateTracing(logger *logrus.Logger) {
}

func updatePowerStoreConnection(powerStoreSvc *service.PowerStoreService, logger *logrus.Logger) {
f := &fs.Fs{Util: &gofsutil.FS{}}
arrays, _, _, err := array.GetPowerStoreArrays(f, defaultStorageSystemConfigFile)
arrays, _, _, err := common.GetPowerStoreArrays(defaultStorageSystemConfigFile, logger)
if err != nil {
logger.WithError(err).Fatal("initialize arrays in controller service")
}
Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module github.com/dell/csm-metrics-powerstore
go 1.14

require (
github.com/dell/csi-powerstore v0.0.0-20210923102620-2b6d0e23ab2e
github.com/dell/gofsutil v1.6.0
github.com/dell/gopowerstore v1.5.0
github.com/dell/gocsi v1.5.0
github.com/dell/gopowerstore v1.6.0
github.com/fsnotify/fsnotify v1.4.9
github.com/golang/mock v1.4.3
github.com/jarcoal/httpmock v1.0.6 // indirect
github.com/onsi/ginkgo v1.14.2 // indirect
github.com/onsi/gomega v1.10.4 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
Expand All @@ -17,6 +18,8 @@ require (
go.opentelemetry.io/otel/exporters/trace/zipkin v0.7.0
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
google.golang.org/grpc v1.38.0
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.20.0
k8s.io/apimachinery v0.20.0
k8s.io/client-go v0.20.0
Expand Down
37 changes: 5 additions & 32 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7 h1:qELHH0AWCvf98Yf+CNIJx9vOZOfHFDDzgDRYsnNk/vs=
github.com/DataDog/sketches-go v0.0.0-20190923095040-43f19ad77ff7/go.mod h1:Q5DbzQ+3AkgGwymQO7aZFNP7ns2lZKGtvRBzRXfdi60=
github.com/HdrHistogram/hdrhistogram-go v1.0.1 h1:GX8GAYDuhlFQnI2fRDHQhTlkHMz8bEn0jTI6LJU0mpw=
github.com/HdrHistogram/hdrhistogram-go v1.0.1/go.mod h1:BWJ+nMSHY3L41Zj7CA3uXnloDp7xxV0YvstAE7nKTaM=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
Expand Down Expand Up @@ -76,9 +74,7 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/container-storage-interface/spec v1.4.0 h1:ozAshSKxpJnYUfmkpZCTYyF/4MYeYlhdXbAvPvfGmkg=
github.com/container-storage-interface/spec v1.4.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand All @@ -89,21 +85,10 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dell/csi-powerstore v0.0.0-20210923102620-2b6d0e23ab2e h1:r+zcottpsZXA/LOZ8m957vTwl6ZEmYFm1c5YUO+01w8=
github.com/dell/csi-powerstore v0.0.0-20210923102620-2b6d0e23ab2e/go.mod h1:Kql3zyUSC5aRCKAlmxY0jVZkpdrtftxpYy+t8J4cx8E=
github.com/dell/dell-csi-extensions/replication v1.0.0 h1:fLcn4xhVO7Xt5t8ZIwDu57vAtL3LWbdYF94W9bpWS/Y=
github.com/dell/dell-csi-extensions/replication v1.0.0/go.mod h1:DbHqsh4vpC+SajnrDSAwWE8n556GSSyzOAEBX7tcCUg=
github.com/dell/gobrick v1.2.0 h1:dlgWgonXG7qoa+SXlek/NkdFBnfxgqSv+8tsHIBIEDg=
github.com/dell/gobrick v1.2.0/go.mod h1:pYN9r3XvIjct/QkEg5mEM+k2L3QBLVaHUZeAMzQgwRg=
github.com/dell/gocsi v1.3.1 h1:YA99j6+kMKiQX/3ERHjKStkAnXWu5sqtk6RE/saMRQk=
github.com/dell/gocsi v1.3.1/go.mod h1:doJru1XfPHSmROXxtAey6eQ8QseoFKaMtA8YaWCb0mU=
github.com/dell/gofsutil v1.6.0 h1:u5PiMJIyecAWpSlPloov1/3LF5OWrcjJwoFF8dWkjcA=
github.com/dell/gofsutil v1.6.0/go.mod h1:98Wpcg7emz4iGgY16fd4MKpnal2SX2hBiwP5ghHlvhg=
github.com/dell/goiscsi v1.1.0/go.mod h1:MfuMjbKWsh/MOb0VDW20C+LFYRIOfWKGiAxWkeM5TKo=
github.com/dell/goiscsi v1.2.0 h1:ocQs4pz2Fw2vr73RVAQBKwpN468SK4TZHPLhU7/FB9A=
github.com/dell/goiscsi v1.2.0/go.mod h1:MfuMjbKWsh/MOb0VDW20C+LFYRIOfWKGiAxWkeM5TKo=
github.com/dell/gopowerstore v1.5.0 h1:Hm4uRaNcCugaWItly38BOlOIxEql28Z8VqC7VIAio7s=
github.com/dell/gopowerstore v1.5.0/go.mod h1:0ziQJ1iuZYDV+P53ua+VeH+rIylYT9WNjGSI/7aPly0=
github.com/dell/gocsi v1.5.0 h1:qi2T6H6JHDo9sJEw24jo6Z88fJszBXfQc3lxOBaUijo=
github.com/dell/gocsi v1.5.0/go.mod h1:nIsIXXB5JpAvOQ0//gtPGULC2+NUddpi5qwpBeMhiLs=
github.com/dell/gopowerstore v1.6.0 h1:CoHJ4DSTGuUEsB0+EBSBoW1EWslrATH0p6YPSSDWaZw=
github.com/dell/gopowerstore v1.6.0/go.mod h1:0ziQJ1iuZYDV+P53ua+VeH+rIylYT9WNjGSI/7aPly0=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
Expand Down Expand Up @@ -375,8 +360,6 @@ github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuK
github.com/open-telemetry/opentelemetry-proto v0.4.0 h1:7EGs7QkdnR039zcQv71/wPLeeUUzqpH855VEWN4IHTE=
github.com/open-telemetry/opentelemetry-proto v0.4.0/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openzipkin/zipkin-go v0.2.2 h1:nY8Hti+WKaP0cRsSeQ026wU03QsM762XBeCXBb9NAWI=
github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
Expand Down Expand Up @@ -421,7 +404,6 @@ github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sirupsen/logrus v0.0.0-20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand Down Expand Up @@ -453,7 +435,6 @@ github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand All @@ -468,10 +449,6 @@ github.com/thecodeteam/gosync v0.1.0/go.mod h1:43QHsngcnWc8GE1aCmi7PEypslflHjCzX
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/uber/jaeger-client-go v2.25.0+incompatible h1:IxcNZ7WRY1Y3G4poYlx24szfsn/3LvK9QHCq9oQw8+U=
github.com/uber/jaeger-client-go v2.25.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk=
github.com/uber/jaeger-lib v2.4.0+incompatible h1:fY7QsGQWiCt8pajv4r7JEvmATdCVaWxXbjwyYwsNaLQ=
github.com/uber/jaeger-lib v2.4.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U=
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
Expand All @@ -495,13 +472,11 @@ go.opentelemetry.io/otel/exporters/otlp v0.7.0/go.mod h1:Qxj/DhsAynmsutiEbuDpDtE
go.opentelemetry.io/otel/exporters/trace/zipkin v0.7.0 h1:8lDisbKLgupie3gB+ZgNZv7kP08vBBjoEb8LvDJSqAg=
go.opentelemetry.io/otel/exporters/trace/zipkin v0.7.0/go.mod h1:IvpoNJ3w0jB5u2fkPVxu8fIf+aX2AkAWgQVHduc8CwQ=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
golang.org/x/crypto v0.0.0-20171023145632-2509b142fb2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down Expand Up @@ -596,9 +571,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20171028101351-661970f62f58/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
121 changes: 121 additions & 0 deletions internal/common/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Copyright (c) 2021 Dell Inc., or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

package common

import (
"context"
"errors"
"fmt"
"io/ioutil"
"path/filepath"
"regexp"
"strconv"

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

"github.com/dell/csm-metrics-powerstore/internal/service"
"github.com/dell/gopowerstore"
"github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"gopkg.in/yaml.v2"
)

const (
// EnvThrottlingRateLimit sets a number of concurrent requests to APi
EnvThrottlingRateLimit = "X_CSI_POWERSTORE_THROTTLING_RATE_LIMIT"
)

// GetPowerStoreArrays parses config.yaml file, initializes gopowerstore Clients and composes map of arrays for ease of access.
// It will return array that can be used as default as a second return parameter.
// If config does not have any array as a default then the first will be returned as a default.
func GetPowerStoreArrays(filePath string, logger *logrus.Logger) (map[string]*service.PowerStoreArray, map[string]string, *service.PowerStoreArray, error) {
type config struct {
Arrays []*service.PowerStoreArray `yaml:"arrays"`
}

data, err := ioutil.ReadFile(filepath.Clean(filePath))
if err != nil {
logger.WithError(err).Errorf("cannot read file %s", filePath)
return nil, nil, nil, err
}

var cfg config
err = yaml.Unmarshal(data, &cfg)
if err != nil {
logger.WithError(err).Errorf("cannot unmarshal data")
return nil, nil, nil, err
}

arrayMap := make(map[string]*service.PowerStoreArray)
mapper := make(map[string]string)
var defaultArray *service.PowerStoreArray
foundDefault := false

if len(cfg.Arrays) == 0 {
return arrayMap, mapper, defaultArray, nil
}

// Safeguard if user doesn't set any array as default, we just use first one
defaultArray = cfg.Arrays[0]

// Convert to map for convenience and init gopowerstore.Client
for _, array := range cfg.Arrays {
array := array
if array == nil {
return arrayMap, mapper, defaultArray, nil
}
if array.GlobalID == "" {
return nil, nil, nil, errors.New("no GlobalID field found in config.yaml, update config.yaml according to the documentation")
}
clientOptions := gopowerstore.NewClientOptions()
clientOptions.SetInsecure(array.Insecure)

if throttlingRateLimit, ok := csictx.LookupEnv(context.Background(), EnvThrottlingRateLimit); ok {
rateLimit, err := strconv.Atoi(throttlingRateLimit)
if err != nil {
logger.Errorf("can't get throttling rate limit, using default")
} else {
clientOptions.SetRateLimit(uint64(rateLimit))
}
}

c, err := gopowerstore.NewClientWithArgs(
array.Endpoint, array.Username, array.Password, clientOptions)
if err != nil {
return nil, nil, nil, status.Errorf(codes.FailedPrecondition,
"unable to create PowerStore client: %s", err.Error())
}
array.Client = c

ips := GetIPListFromString(array.Endpoint)
if ips == nil {
return nil, nil, nil, fmt.Errorf("can't get ips from endpoint: %s", array.Endpoint)
}

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
mapper[ip] = array.GlobalID
if array.IsDefault && !foundDefault {
defaultArray = array
foundDefault = true
}
}

return arrayMap, mapper, defaultArray, nil
}

// GetIPListFromString returns list of ips in string form found in input string
// A return value of nil indicates no match
func GetIPListFromString(input string) []string {
re := regexp.MustCompile(`(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}`)
return re.FindAllString(input, -1)
}
68 changes: 68 additions & 0 deletions internal/common/common_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2021 Dell Inc., or its subsidiaries. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0

package common_test

import (
"context"
"testing"

"github.com/dell/csm-metrics-powerstore/internal/common"
csictx "github.com/dell/gocsi/context"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

func Test_Run(t *testing.T) {

tests := map[string]func(t *testing.T) (filePath string, env map[string]string, expectError bool){

"success": func(*testing.T) (string, map[string]string, bool) {
return "testdata/sample-config.yaml", map[string]string{common.EnvThrottlingRateLimit: "123"}, false
},
"invalid throttling value": func(*testing.T) (string, map[string]string, bool) {
return "testdata/sample-config.yaml", map[string]string{common.EnvThrottlingRateLimit: "abc"}, false
},
"file doesn't exist": func(*testing.T) (string, map[string]string, bool) {
return "testdata/no-file.yaml", nil, true
},
"file format": func(*testing.T) (string, map[string]string, bool) {
return "testdata/invalid-format.yaml", nil, true
},
"no global id": func(*testing.T) (string, map[string]string, bool) {
return "testdata/no-global-id.yaml", nil, true
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {

logger := logrus.New()
filePath, envs, expectError := test(t)

for k, v := range envs {
csictx.Setenv(context.Background(), k, v)
}

arrays, mapper, defaultArray, err := common.GetPowerStoreArrays(filePath, logger)

if expectError {
assert.Nil(t, arrays)
assert.Nil(t, mapper)
assert.Nil(t, defaultArray)
assert.NotNil(t, err)
} else {
assert.NotNil(t, arrays)
assert.NotNil(t, mapper)
assert.NotNil(t, defaultArray)
assert.Nil(t, err)
}

})
}
}
2 changes: 2 additions & 0 deletions internal/common/testdata/invalid-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invalid_format

9 changes: 9 additions & 0 deletions internal/common/testdata/no-global-id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
arrays:
- endpoint: "https://10.0.0.1/api/rest"
username: "user"
password: "password"
skipCertificateValidation: true
isDefault: true
blockProtocol: "auto"
nasName: "nas-server"

17 changes: 17 additions & 0 deletions internal/common/testdata/sample-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
arrays:
- endpoint: "https://10.0.0.1/api/rest"
globalID: "unique"
username: "user"
password: "password"
skipCertificateValidation: true
isDefault: true
blockProtocol: "auto"
nasName: "nas-server"

- endpoint: "https://11.0.0.1/api/rest"
globalID: "unique"
username: "user"
password: "password"
skipCertificateValidation: true
blockProtocol: "FC"

3 changes: 1 addition & 2 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

tracer "github.com/dell/csm-metrics-powerstore/opentelemetry/tracers"

"github.com/dell/csi-powerstore/pkg/array"
"github.com/dell/gopowerstore"

"github.com/dell/csm-metrics-powerstore/internal/k8s"
Expand Down Expand Up @@ -59,7 +58,7 @@ type PowerStoreService struct {
MaxPowerStoreConnections int
Logger *logrus.Logger
PowerStoreClients map[string]PowerStoreClient
DefaultPowerStoreArray *array.PowerStoreArray
DefaultPowerStoreArray *PowerStoreArray
VolumeFinder VolumeFinder
}

Expand Down
Loading

0 comments on commit df88484

Please sign in to comment.