-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fallback logic to retrieve CHAP info from controller
- Loading branch information
Showing
14 changed files
with
457 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2022 NetApp, Inc. All Rights Reserved. | ||
|
||
package controllerAPI | ||
|
||
//go:generate mockgen -destination=../../../mocks/mock_frontend/mock_csi/mock_controller_api/mock_controller_api.go github.com/netapp/trident/frontend/csi/controller_api TridentController | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
|
||
"github.com/netapp/trident/utils" | ||
) | ||
|
||
type TridentController interface { | ||
InvokeAPI( | ||
ctx context.Context, requestBody []byte, method string, resourcePath string, redactRequestBody, | ||
redactResponseBody bool, | ||
) (*http.Response, []byte, error) | ||
CreateNode(ctx context.Context, node *utils.Node) (CreateNodeResponse, error) | ||
GetNodes(ctx context.Context) ([]string, error) | ||
DeleteNode(ctx context.Context, name string) error | ||
GetChap(ctx context.Context, volume, node string) (*utils.IscsiChapInfo, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2022 NetApp, Inc. All Rights Reserved. | ||
|
||
package csi | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/container-storage-interface/spec/lib/go/csi" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
|
||
mockControllerAPI "github.com/netapp/trident/mocks/mock_frontend/mock_csi/mock_controller_api" | ||
"github.com/netapp/trident/utils" | ||
) | ||
|
||
func TestUpdateChapInfoFromController_Success(t *testing.T) { | ||
testCtx := context.Background() | ||
volumeName := "foo" | ||
nodeName := "bar" | ||
expectedChapInfo := utils.IscsiChapInfo{ | ||
UseCHAP: true, | ||
IscsiUsername: "user", | ||
IscsiInitiatorSecret: "pass", | ||
IscsiTargetUsername: "user2", | ||
IscsiTargetSecret: "pass2", | ||
} | ||
|
||
mockCtrl := gomock.NewController(t) | ||
mockClient := mockControllerAPI.NewMockTridentController(mockCtrl) | ||
mockClient.EXPECT().GetChap(testCtx, volumeName, nodeName).Return(&expectedChapInfo, nil) | ||
nodeServer := &Plugin{ | ||
nodeName: nodeName, | ||
role: CSINode, | ||
restClient: mockClient, | ||
} | ||
|
||
fakeRequest := &csi.NodeStageVolumeRequest{VolumeId: volumeName} | ||
testPublishInfo := &utils.VolumePublishInfo{} | ||
|
||
err := nodeServer.updateChapInfoFromController(testCtx, fakeRequest, testPublishInfo) | ||
assert.Nil(t, err, "Unexpected error") | ||
assert.EqualValues(t, expectedChapInfo, testPublishInfo.IscsiAccessInfo.IscsiChapInfo) | ||
} | ||
|
||
func TestUpdateChapInfoFromController_Error(t *testing.T) { | ||
testCtx := context.Background() | ||
volumeName := "foo" | ||
nodeName := "bar" | ||
expectedChapInfo := utils.IscsiChapInfo{ | ||
UseCHAP: true, | ||
IscsiUsername: "user", | ||
IscsiInitiatorSecret: "pass", | ||
IscsiTargetUsername: "user2", | ||
IscsiTargetSecret: "pass2", | ||
} | ||
|
||
mockCtrl := gomock.NewController(t) | ||
mockClient := mockControllerAPI.NewMockTridentController(mockCtrl) | ||
mockClient.EXPECT().GetChap(testCtx, volumeName, nodeName).Return(&expectedChapInfo, fmt.Errorf("some error")) | ||
nodeServer := &Plugin{ | ||
nodeName: nodeName, | ||
role: CSINode, | ||
restClient: mockClient, | ||
} | ||
|
||
fakeRequest := &csi.NodeStageVolumeRequest{VolumeId: volumeName} | ||
testPublishInfo := &utils.VolumePublishInfo{} | ||
|
||
err := nodeServer.updateChapInfoFromController(testCtx, fakeRequest, testPublishInfo) | ||
assert.NotNil(t, err, "Unexpected success") | ||
assert.NotEqualValues(t, expectedChapInfo, testPublishInfo.IscsiAccessInfo.IscsiChapInfo) | ||
assert.EqualValues(t, utils.IscsiChapInfo{}, testPublishInfo.IscsiAccessInfo.IscsiChapInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.