Skip to content

Commit 2c477c3

Browse files
authored
Nvme utils refactor
Add nvme package and unit tests
1 parent 0912ca2 commit 2c477c3

15 files changed

+1681
-678
lines changed

core/orchestrator_core.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ import (
3232
storageclass "github.com/netapp/trident/storage_class"
3333
drivers "github.com/netapp/trident/storage_drivers"
3434
"github.com/netapp/trident/storage_drivers/fake"
35-
"github.com/netapp/trident/utils"
3635
"github.com/netapp/trident/utils/errors"
3736
"github.com/netapp/trident/utils/fcp"
3837
"github.com/netapp/trident/utils/filesystem"
3938
"github.com/netapp/trident/utils/iscsi"
4039
"github.com/netapp/trident/utils/models"
4140
"github.com/netapp/trident/utils/mount"
41+
"github.com/netapp/trident/utils/nvme"
4242
)
4343

4444
const (
@@ -3643,7 +3643,9 @@ func (o *TridentOrchestrator) AttachVolume(
36433643
} else {
36443644
var err error
36453645
if publishInfo.SANType == sa.NVMe {
3646-
err = utils.AttachNVMeVolumeRetry(ctx, volumeName, mountpoint, publishInfo, map[string]string{}, utils.NVMeAttachTimeout)
3646+
nvmeHandler := nvme.NewNVMeHandler()
3647+
err = nvmeHandler.AttachNVMeVolumeRetry(ctx, volumeName, mountpoint, publishInfo, map[string]string{},
3648+
nvme.NVMeAttachTimeout)
36473649
}
36483650

36493651
if publishInfo.SANType == sa.ISCSI {

frontend/csi/node_server.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/netapp/trident/utils/filesystem"
3838
"github.com/netapp/trident/utils/iscsi"
3939
"github.com/netapp/trident/utils/models"
40+
"github.com/netapp/trident/utils/nvme"
4041
"github.com/netapp/trident/utils/osutils"
4142
"github.com/netapp/trident/utils/smb"
4243
)
@@ -64,7 +65,7 @@ var (
6465
fcpUtils = utils.FcpUtils
6566

6667
publishedISCSISessions, currentISCSISessions models.ISCSISessions
67-
publishedNVMeSessions, currentNVMeSessions utils.NVMeSessions
68+
publishedNVMeSessions, currentNVMeSessions nvme.NVMeSessions
6869
// NVMeNamespacesFlushRetry - Non-persistent map of Namespaces to maintain the flush errors if any.
6970
// During NodeUnstageVolume, Trident shall return success after specific wait time (nvmeMaxFlushWaitDuration).
7071
NVMeNamespacesFlushRetry = make(map[string]time.Time)
@@ -2515,8 +2516,8 @@ func (p *Plugin) nodeStageNVMeVolume(
25152516
publishInfo.NVMeTargetIPs = strings.Split(req.PublishContext["nvmeTargetIPs"], ",")
25162517
publishInfo.SANType = req.PublishContext["SANType"]
25172518

2518-
err := utils.AttachNVMeVolumeRetry(
2519-
ctx, req.VolumeContext["internalName"], "", publishInfo, req.GetSecrets(), utils.NVMeAttachTimeout,
2519+
err := p.nvmeHandler.AttachNVMeVolumeRetry(
2520+
ctx, req.VolumeContext["internalName"], "", publishInfo, req.GetSecrets(), nvme.NVMeAttachTimeout,
25202521
)
25212522
if err != nil {
25222523
return err
@@ -2831,7 +2832,7 @@ func (p *Plugin) performNVMeSelfHealing(ctx context.Context) {
28312832
publishedNVMeSessions.ResetRemediationForAll()
28322833

28332834
// Reset current sessions
2834-
currentNVMeSessions = utils.NVMeSessions{}
2835+
currentNVMeSessions = nvme.NVMeSessions{}
28352836

28362837
// Populate the current sessions
28372838
if err := p.nvmeHandler.PopulateCurrentNVMeSessions(ctx, &currentNVMeSessions); err != nil {
@@ -2849,7 +2850,7 @@ func (p *Plugin) performNVMeSelfHealing(ctx context.Context) {
28492850
Logc(ctx).Debug("NVMe healing finished.")
28502851
}
28512852

2852-
func (p *Plugin) fixNVMeSessions(ctx context.Context, stopAt time.Time, subsystems []utils.NVMeSubsystem) {
2853+
func (p *Plugin) fixNVMeSessions(ctx context.Context, stopAt time.Time, subsystems []nvme.NVMeSubsystem) {
28532854
for index, sub := range subsystems {
28542855
// If the subsystem is not present in the published NVMe sessions, we don't need to rectify its sessions.
28552856
if !publishedNVMeSessions.CheckNVMeSessionExists(sub.NQN) {

frontend/csi/node_server_test.go

+11-10
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import (
2121
mockcore "github.com/netapp/trident/mocks/mock_core"
2222
mockControllerAPI "github.com/netapp/trident/mocks/mock_frontend/mock_csi/mock_controller_api"
2323
mockNodeHelpers "github.com/netapp/trident/mocks/mock_frontend/mock_csi/mock_node_helpers"
24-
mockUtils "github.com/netapp/trident/mocks/mock_utils"
2524
"github.com/netapp/trident/mocks/mock_utils/mock_devices"
2625
"github.com/netapp/trident/mocks/mock_utils/mock_iscsi"
2726
"github.com/netapp/trident/mocks/mock_utils/mock_mount"
27+
mock_nvme "github.com/netapp/trident/mocks/mock_utils/nvme"
2828
"github.com/netapp/trident/pkg/collection"
2929
"github.com/netapp/trident/pkg/convert"
3030
sa "github.com/netapp/trident/storage_attribute"
@@ -35,6 +35,7 @@ import (
3535
"github.com/netapp/trident/utils/iscsi"
3636
"github.com/netapp/trident/utils/models"
3737
"github.com/netapp/trident/utils/mount"
38+
"github.com/netapp/trident/utils/nvme"
3839
"github.com/netapp/trident/utils/osutils"
3940
)
4041

@@ -1543,22 +1544,22 @@ func TestUpdateNodePublicationState_SuccessfullyUpdatesNodeAsCleaned(t *testing.
15431544

15441545
func TestPerformNVMeSelfHealing(t *testing.T) {
15451546
mockCtrl := gomock.NewController(t)
1546-
mockNVMeHandler := mockUtils.NewMockNVMeInterface(mockCtrl)
1547+
mockNVMeHandler := mock_nvme.NewMockNVMeInterface(mockCtrl)
15471548
nodeServer := &Plugin{nvmeHandler: mockNVMeHandler}
15481549

15491550
// Empty Published sessions case.
15501551
nodeServer.performNVMeSelfHealing(ctx)
15511552

15521553
// Error populating current sessions.
1553-
publishedNVMeSessions.AddNVMeSession(utils.NVMeSubsystem{NQN: "nqn"}, []string{})
1554+
publishedNVMeSessions.AddNVMeSession(nvme.NVMeSubsystem{NQN: "nqn"}, []string{})
15541555
mockNVMeHandler.EXPECT().PopulateCurrentNVMeSessions(ctx, gomock.Any()).
15551556
Return(errors.New("failed to populate current sessions"))
15561557

15571558
nodeServer.performNVMeSelfHealing(ctx)
15581559

15591560
// Self-healing process done.
15601561
mockNVMeHandler.EXPECT().PopulateCurrentNVMeSessions(ctx, gomock.Any()).Return(nil)
1561-
mockNVMeHandler.EXPECT().InspectNVMeSessions(ctx, gomock.Any(), gomock.Any()).Return([]utils.NVMeSubsystem{})
1562+
mockNVMeHandler.EXPECT().InspectNVMeSessions(ctx, gomock.Any(), gomock.Any()).Return([]nvme.NVMeSubsystem{})
15621563

15631564
nodeServer.performNVMeSelfHealing(ctx)
15641565
// Cleanup of global objects.
@@ -1567,10 +1568,10 @@ func TestPerformNVMeSelfHealing(t *testing.T) {
15671568

15681569
func TestFixNVMeSessions(t *testing.T) {
15691570
mockCtrl := gomock.NewController(t)
1570-
mockNVMeHandler := mockUtils.NewMockNVMeInterface(mockCtrl)
1571+
mockNVMeHandler := mock_nvme.NewMockNVMeInterface(mockCtrl)
15711572
nodeServer := &Plugin{nvmeHandler: mockNVMeHandler}
1572-
subsystem1 := utils.NVMeSubsystem{NQN: "nqn1"}
1573-
subsystems := []utils.NVMeSubsystem{subsystem1}
1573+
subsystem1 := nvme.NVMeSubsystem{NQN: "nqn1"}
1574+
subsystems := []nvme.NVMeSubsystem{subsystem1}
15741575

15751576
// Subsystem not present in published sessions case.
15761577
nodeServer.fixNVMeSessions(ctx, time.UnixMicro(0), subsystems)
@@ -1751,7 +1752,7 @@ func TestNodeRegisterWithController_Success(t *testing.T) {
17511752
mockCtrl := gomock.NewController(t)
17521753
mockClient := mockControllerAPI.NewMockTridentController(mockCtrl)
17531754
mockOrchestrator := mockcore.NewMockOrchestrator(mockCtrl)
1754-
mockNVMeHandler := mockUtils.NewMockNVMeInterface(mockCtrl)
1755+
mockNVMeHandler := mock_nvme.NewMockNVMeInterface(mockCtrl)
17551756

17561757
iscsiClient, _ := iscsi.New()
17571758
// Create a node server plugin
@@ -1796,7 +1797,7 @@ func TestNodeRegisterWithController_TopologyLabels(t *testing.T) {
17961797
mockCtrl := gomock.NewController(t)
17971798
mockClient := mockControllerAPI.NewMockTridentController(mockCtrl)
17981799
mockOrchestrator := mockcore.NewMockOrchestrator(mockCtrl)
1799-
mockNVMeHandler := mockUtils.NewMockNVMeInterface(mockCtrl)
1800+
mockNVMeHandler := mock_nvme.NewMockNVMeInterface(mockCtrl)
18001801
iscsiClient, _ := iscsi.New()
18011802

18021803
// Create a node server plugin
@@ -1882,7 +1883,7 @@ func TestNodeRegisterWithController_Failure(t *testing.T) {
18821883
mockCtrl := gomock.NewController(t)
18831884
mockClient := mockControllerAPI.NewMockTridentController(mockCtrl)
18841885
mockOrchestrator := mockcore.NewMockOrchestrator(mockCtrl)
1885-
mockNVMeHandler := mockUtils.NewMockNVMeInterface(mockCtrl)
1886+
mockNVMeHandler := mock_nvme.NewMockNVMeInterface(mockCtrl)
18861887
iscsiClient, _ := iscsi.New()
18871888

18881889
// Create a node server plugin

frontend/csi/plugin.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
controllerhelpers "github.com/netapp/trident/frontend/csi/controller_helpers"
2222
nodehelpers "github.com/netapp/trident/frontend/csi/node_helpers"
2323
. "github.com/netapp/trident/logging"
24-
"github.com/netapp/trident/utils"
2524
"github.com/netapp/trident/utils/devices"
2625
"github.com/netapp/trident/utils/errors"
2726
execCmd "github.com/netapp/trident/utils/exec"
@@ -30,6 +29,7 @@ import (
3029
"github.com/netapp/trident/utils/iscsi"
3130
"github.com/netapp/trident/utils/models"
3231
"github.com/netapp/trident/utils/mount"
32+
"github.com/netapp/trident/utils/nvme"
3333
"github.com/netapp/trident/utils/osutils"
3434
)
3535

@@ -81,7 +81,7 @@ type Plugin struct {
8181
stopNodePublicationLoop chan bool
8282
nodePublicationTimer *time.Timer
8383

84-
nvmeHandler utils.NVMeInterface
84+
nvmeHandler nvme.NVMeInterface
8585

8686
nvmeSelfHealingTicker *time.Ticker
8787
nvmeSelfHealingChannel chan struct{}
@@ -198,7 +198,7 @@ func NewNodePlugin(
198198
opCache: sync.Map{},
199199
iSCSISelfHealingInterval: iSCSISelfHealingInterval,
200200
iSCSISelfHealingWaitTime: iSCSIStaleSessionWaitTime,
201-
nvmeHandler: utils.NewNVMeHandler(),
201+
nvmeHandler: nvme.NewNVMeHandler(),
202202
nvmeSelfHealingInterval: nvmeSelfHealingInterval,
203203
iscsi: iscsiClient,
204204
// NewClient() must plugin default implementation of the various package clients.
@@ -308,7 +308,7 @@ func NewAllInOnePlugin(
308308
opCache: sync.Map{},
309309
iSCSISelfHealingInterval: iSCSISelfHealingInterval,
310310
iSCSISelfHealingWaitTime: iSCSIStaleSessionWaitTime,
311-
nvmeHandler: utils.NewNVMeHandler(),
311+
nvmeHandler: nvme.NewNVMeHandler(),
312312
nvmeSelfHealingInterval: nvmeSelfHealingInterval,
313313
iscsi: iscsiClient,
314314
fcp: fcpClient,

mocks/mock_utils/mock_fcp/mock_fcp_client.go

+16-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)