Skip to content

Commit

Permalink
Fixed failing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
santhoshatdell committed Oct 22, 2024
1 parent 0f997b0 commit fdba537
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 58 deletions.
31 changes: 18 additions & 13 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,51 +134,56 @@ func (s *Service) Init() error {
}

var initiators []string
var useNVME, useFC bool

switch arr.BlockProtocol {
case common.NVMETCPTransport:
if len(nvmeInitiators) == 0 {
log.Errorf("NVMeTCP transport was requested but NVMe initiator is not available")
}
s.useNVME[arr.GlobalID] = true
s.useFC[arr.GlobalID] = false
useNVME = true
useFC = false
case common.NVMEFCTransport:
if len(nvmeInitiators) == 0 {
log.Errorf("NVMeFC transport was requested but NVMe initiator is not available")
}
s.useNVME[arr.GlobalID] = true
s.useFC[arr.GlobalID] = true
useNVME = true
useFC = true
case common.ISCSITransport:
if len(iscsiInitiators) == 0 {
log.Errorf("iSCSI transport was requested but iSCSI initiator is not available")
}
s.useNVME[arr.GlobalID] = false
s.useFC[arr.GlobalID] = false
useNVME = false
useFC = false
case common.FcTransport:
if len(fcInitiators) == 0 {
log.Errorf("FC transport was requested but FC initiator is not available")
}
s.useNVME[arr.GlobalID] = false
s.useFC[arr.GlobalID] = true
useNVME = false
useFC = true
default:
s.useNVME[arr.GlobalID] = len(nvmeInitiators) > 0
s.useFC[arr.GlobalID] = len(fcInitiators) > 0
useNVME = len(nvmeInitiators) > 0
useFC = len(fcInitiators) > 0
}
if s.useNVME[arr.GlobalID] {
if useNVME {
initiators = nvmeInitiators
if s.useFC[arr.GlobalID] {
if useFC {
log.Infof("NVMeFC Protocol is requested")
} else {
log.Infof("NVMeTCP Protocol is requested")
}
} else if s.useFC[arr.GlobalID] {
} else if useFC {
initiators = fcInitiators
log.Infof("FC Protocol is requested")
} else {
initiators = iscsiInitiators
log.Infof("iSCSI Protocol is requested")
}

// store the values in the array list for later use
s.useNVME[arr.GlobalID] = useNVME
s.useFC[arr.GlobalID] = useFC

err = s.setupHost(initiators, arr.GetClient(), arr.GetIP(), arr.GetGlobalID())
if err != nil {
log.Errorf("can't setup host on %s: %s", arr.Endpoint, err.Error())
Expand Down
88 changes: 43 additions & 45 deletions pkg/node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ func setVariables() {
iscsiLib: iscsiLibMock,
nvmeLib: nvmeLibMock,
nodeID: validNodeID,
useFC: false,
useNVME: false,
initialized: true,
isPodmonEnabled: false,
}
nodeSvc.iscsiTargets = make(map[string][]string)
nodeSvc.nvmeTargets = make(map[string][]string)
nodeSvc.useFC = make(map[string]bool)
nodeSvc.useNVME = make(map[string]bool)
old := ReachableEndPoint
func() { ReachableEndPoint = old }()
ReachableEndPoint = func(ip string) bool {
Expand Down Expand Up @@ -549,7 +549,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
ginkgo.It("should create FC host", func() {
nodeSvc.Arrays()[firstValidIP].BlockProtocol = common.FcTransport
nodeSvc.nodeID = ""
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
conn, _ := net.Dial("udp", "127.0.0.1:80")
fsMock.On("NetDial", mock.Anything).Return(
conn,
Expand Down Expand Up @@ -598,7 +598,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
ginkgo.It("should create NVMe host", func() {
nodeSvc.Arrays()[firstValidIP].BlockProtocol = common.NVMEFCTransport
nodeSvc.nodeID = ""
nodeSvc.useNVME = true
nodeSvc.useNVME[firstValidIP] = true
fsMock.On("ReadFile", mock.Anything).Return([]byte("my-host-id"), nil)
conn, _ := net.Dial("udp", "127.0.0.1:80")
fsMock.On("NetDial", mock.Anything).Return(
Expand Down Expand Up @@ -715,7 +715,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
}, nil)

arrays := getTestArrays()
nodeSvc.useNVME = true
nodeSvc.useNVME["unique"] = true
clientMock.On("GetStorageISCSITargetAddresses", mock.Anything).
Return([]gopowerstore.IPPoolAddress{}, nil)
clientMock.On("GetStorageNVMETCPTargetAddresses", mock.Anything).
Expand All @@ -726,7 +726,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
NVMeNQN: validNVMEInitiators[0],
}, nil)
err := nodeSvc.nodeProbe(context.Background(), arrays["gid1"])
nodeSvc.useNVME = false
nodeSvc.useNVME["unique"] = false
gomega.Expect(err.Error()).To(gomega.ContainSubstring("no active nvme sessions"))
})
})
Expand Down Expand Up @@ -788,11 +788,11 @@ var _ = ginkgo.Describe("CSINodeService", func() {
NVMeNQN: validNVMEInitiators[0],
}, nil)
nodeSvc.useNFS = true
nodeSvc.useNVME = true
nodeSvc.useNVME["unique"] = true
arrays := getTestArrays()
err := nodeSvc.nodeProbe(context.Background(), arrays["gid1"])
nodeSvc.useNFS = false
nodeSvc.useNVME = false
nodeSvc.useNVME["unique"] = false
gomega.Expect(err).To(gomega.BeNil())
})
})
Expand Down Expand Up @@ -871,10 +871,10 @@ var _ = ginkgo.Describe("CSINodeService", func() {
Return([]gopowerstore.IPPoolAddress{}, nil)
arrays := getTestArrays()
nodeSvc.useNFS = true
nodeSvc.useNVME = true
nodeSvc.useNVME["unique"] = true
nodeSvc.nvmeTargets["unique"] = []string{"nqn.1988-11.com.dell.mock:00:e6e2d5b871f1403E169D0"}
err := nodeSvc.nodeProbe(context.Background(), arrays["gid1"])
nodeSvc.useNVME = false
nodeSvc.useNVME["unique"] = false
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(nodeSvc.useNFS).To(gomega.BeFalse())
})
Expand Down Expand Up @@ -967,11 +967,11 @@ var _ = ginkgo.Describe("CSINodeService", func() {
}, nil)

arrays := getTestArrays()
if nodeSvc.useNVME {
nodeSvc.useNVME = false
if nodeSvc.useNVME["unique"] {
nodeSvc.useNVME["unique"] = false
}
if !nodeSvc.useFC {
nodeSvc.useFC = true
if !nodeSvc.useFC["unique"] {
nodeSvc.useFC["unique"] = true
}

err := nodeSvc.nodeProbe(context.Background(), arrays["gid1"])
Expand All @@ -991,15 +991,15 @@ var _ = ginkgo.Describe("CSINodeService", func() {
}, nil)

arrays := getTestArrays()
if nodeSvc.useNVME {
nodeSvc.useNVME = false
if nodeSvc.useNVME["unique"] {
nodeSvc.useNVME["unique"] = false
}
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true

err := nodeSvc.nodeProbe(context.Background(), arrays["gid1"])
gomega.Expect(err).ToNot(gomega.BeNil())
if nodeSvc.useFC {
nodeSvc.useFC = false
if nodeSvc.useFC["unique"] {
nodeSvc.useFC["unique"] = false
}
})
})
Expand Down Expand Up @@ -1030,8 +1030,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("using NVMeFC", func() {
ginkgo.It("should successfully stage NVMeFC volume", func() {
nodeSvc.useNVME = true
nodeSvc.useFC = true
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = true
nvmeConnectorMock.On("ConnectVolume", mock.Anything, gobrick.NVMeVolumeInfo{
Targets: validNVMEFCTargetInfo,
WWN: validDeviceWWN,
Expand All @@ -1052,7 +1052,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("using FC", func() {
ginkgo.It("should successfully stage FC volume", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
fcConnectorMock.On("ConnectVolume", mock.Anything, gobrick.FCVolumeInfo{
Targets: validFCTargetsInfo,
Lun: validLUNIDINT,
Expand Down Expand Up @@ -1410,8 +1410,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {
})

ginkgo.It("should fail [nvmefcTargets]", func() {
nodeSvc.useNVME = true
nodeSvc.useFC = true
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = true
res, err := nodeSvc.NodeStageVolume(context.Background(), &csi.NodeStageVolumeRequest{
VolumeId: validBlockVolumeID,
PublishContext: map[string]string{
Expand All @@ -1428,7 +1428,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
})

ginkgo.It("should fail [fcTargets]", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
res, err := nodeSvc.NodeStageVolume(context.Background(), &csi.NodeStageVolumeRequest{
VolumeId: validBlockVolumeID,
PublishContext: map[string]string{
Expand Down Expand Up @@ -1675,7 +1675,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
})

ginkgo.It("should succeed [FC]", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
mountInfo := []gofsutil.Info{
{
Device: validDevName,
Expand Down Expand Up @@ -1706,7 +1706,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {
})

ginkgo.It("should succeed [NVMe]", func() {
nodeSvc.useNVME = true
nodeSvc.useNVME["unique"] = true
mountInfo := []gofsutil.Info{
{
Device: validDevName,
Expand Down Expand Up @@ -3486,7 +3486,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("using FC", func() {
ginkgo.It("should return FC topology segments", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
conn, _ := net.Dial("udp", "127.0.0.1:80")
fsMock.On("NetDial", mock.Anything).Return(
conn,
Expand Down Expand Up @@ -3536,7 +3536,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("reusing host", func() {
ginkgo.It("should properly deal with additional IPs", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
nodeID := nodeSvc.nodeID
nodeSvc.nodeID = nodeID + "-" + "192.168.0.1"
nodeSvc.reusedHost = true
Expand Down Expand Up @@ -3589,7 +3589,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("there is no ip in nodeID", func() {
ginkgo.It("should not return FC topology key", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
nodeID := nodeSvc.nodeID
nodeSvc.nodeID = "nodeid-with-no-ip"
nodeSvc.reusedHost = true
Expand Down Expand Up @@ -3643,7 +3643,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("we can not get info about hosts from array", func() {
ginkgo.It("should not return FC topology key", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
e := "internal error"
clientMock.On("GetHostByName", mock.Anything, nodeSvc.nodeID).
Return(gopowerstore.Host{}, errors.New(e))
Expand Down Expand Up @@ -3671,7 +3671,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("host initiators is empty", func() {
ginkgo.It("should not return FC topology key", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
clientMock.On("GetHostByName", mock.Anything, nodeSvc.nodeID).
Return(gopowerstore.Host{
ID: "host-id",
Expand Down Expand Up @@ -3702,7 +3702,7 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("there is no active sessions", func() {
ginkgo.It("should not return FC topology key", func() {
nodeSvc.useFC = true
nodeSvc.useFC["unique"] = true
conn, _ := net.Dial("udp", "127.0.0.1:80")
fsMock.On("NetDial", mock.Anything).Return(
conn,
Expand Down Expand Up @@ -3743,8 +3743,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("using NVMeFC", func() {
ginkgo.It("should return NVMeFC topology segments", func() {
nodeSvc.useNVME = true
nodeSvc.useFC = true
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = true
clientMock.On("GetCluster", mock.Anything).
Return(gopowerstore.Cluster{
Name: validClusterName,
Expand Down Expand Up @@ -3782,8 +3782,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("NVMeFC targets cannot be discovered", func() {
ginkgo.It("should not return NVMeFC topology segments", func() {
nodeSvc.useNVME = true
nodeSvc.useFC = true
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = true
clientMock.On("GetCluster", mock.Anything).
Return(gopowerstore.Cluster{
Name: validClusterName,
Expand Down Expand Up @@ -3821,8 +3821,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("using NVMeTCP", func() {
ginkgo.It("should return NVMeTCP topology segments", func() {
nodeSvc.useNVME = true
nodeSvc.useFC = false
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = false
clientMock.On("GetStorageISCSITargetAddresses", mock.Anything).Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
Expand Down Expand Up @@ -3867,8 +3867,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {
ginkgo.It("should not return nvme topology key", func() {
goiscsi.GOISCSIMock.InduceDiscoveryError = true
gonvme.GONVMEMock.InduceDiscoveryError = true
nodeSvc.useNVME = true
nodeSvc.useFC = false
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = false
clientMock.On("GetStorageISCSITargetAddresses", mock.Anything).Return([]gopowerstore.IPPoolAddress{
{
Address: "192.168.1.1",
Expand Down Expand Up @@ -3912,8 +3912,8 @@ var _ = ginkgo.Describe("CSINodeService", func() {

ginkgo.When("we cannot get NVMeTCP targets from the array", func() {
ginkgo.It("should not return NVMeTCP topology segments", func() {
nodeSvc.useNVME = true
nodeSvc.useFC = false
nodeSvc.useNVME["unique"] = true
nodeSvc.useFC["unique"] = false
e := "internalerror"
clientMock.On("GetStorageISCSITargetAddresses", mock.Anything).Return([]gopowerstore.IPPoolAddress{
{
Expand Down Expand Up @@ -4150,7 +4150,6 @@ func TestInitConnectors(t *testing.T) {
fcConnector: nil,
iscsiLib: nil,
nodeID: validNodeID,
useFC: false,
initialized: true,
}
nodeSvc.SetArrays(arrays)
Expand All @@ -4169,7 +4168,6 @@ func TestGetNodeOptions(t *testing.T) {
fcConnector: nil,
iscsiLib: nil,
nodeID: validNodeID,
useFC: false,
initialized: true,
}
nodeSvc.SetArrays(arrays)
Expand Down

0 comments on commit fdba537

Please sign in to comment.