Skip to content

Commit

Permalink
[ISSUE-1160] Disk Eject: Add LED state to DriveCR (#1161)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrzej Zukowski <[email protected]>
  • Loading branch information
Andrzej-Zukowski authored May 27, 2024
1 parent e50c138 commit bd2fe18
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/v1/drivecrd/drive_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func (in *Drive) Equals(drive *api.Drive) bool {
in.Spec.Health == drive.Health &&
in.Spec.Type == drive.Type &&
in.Spec.Size == drive.Size &&
in.Spec.Path == drive.Path
in.Spec.Path == drive.Path &&
in.Spec.LEDState == drive.LEDState
}

func (in *Drive) GetDriveDescription() string {
Expand Down
1 change: 1 addition & 0 deletions pkg/crcontrollers/drive/drivecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ func (c *Controller) locateDriveLED(ctx context.Context, log *logrus.Entry, driv
c.eventRecorder.Eventf(drive, eventing.DriveLocateLEDFailed, eventMsg)
} else {
// send warning level alert (warning for attention), good level closes issue, need only send message
drive.Spec.LEDState = fmt.Sprintf("%d", status.Status)
eventMsg := fmt.Sprintf("Drive successfully removed from CSI, and ready for physical removal, %s", drive.GetDriveDescription())
c.eventRecorder.Eventf(drive, eventing.DriveReadyForPhysicalRemoval, eventMsg)
}
Expand Down
39 changes: 39 additions & 0 deletions pkg/crcontrollers/drive/drivecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,45 @@ func TestDriveController_locateDriveLED(t *testing.T) {
})
}

func TestDriveController_handleDriveUsageRemovingWithLED(t *testing.T) {
k8SClientset := fake.NewSimpleClientset()
eventInter := k8SClientset.CoreV1().Events(testNs)
scheme, err := k8s.PrepareScheme()
if err != nil {
log.Fatalf("fail to prepare kubernetes scheme, error: %s", err)
return
}

logr := logrus.New()
eventRecorder, err := events.New("baremetal-csi-node", "434aa7b1-8b8a-4ae8-92f9-1cc7e09a9030", eventInter, scheme, logr)
if err != nil {
log.Fatalf("fail to create events recorder, error: %s", err)
return
}

kubeClient := setup()
dc := NewController(kubeClient, nodeID, &mocks.MockDriveMgrClient{}, eventRecorder, testLogger)
assert.NotNil(t, dc)
assert.NotNil(t, dc.crHelper)

t.Run("Check locate drive state", func(t *testing.T) {
expectedD := testCRDrive2.DeepCopy()
assert.NotNil(t, expectedD)
expectedD.Spec.Usage = apiV1.DriveUsageRemoving
expectedD.Spec.LEDState = fmt.Sprintf("%d", apiV1.LocateStatusOff)
assert.Nil(t, dc.client.CreateCR(testCtx, expectedD.Name, expectedD))

res, err := dc.handleDriveUpdate(testCtx, dc.log, expectedD)
assert.NotNil(t, res)
assert.Nil(t, err)
assert.Equal(t, res, update)
assert.Equal(t, expectedD.Spec.Usage, apiV1.DriveUsageRemoved)
assert.Equal(t, expectedD.Spec.LEDState, fmt.Sprintf("%d", apiV1.LocateStatusOn))

assert.Nil(t, dc.client.DeleteCR(testCtx, expectedD))
})
}

func TestDriveController_handleDriveUsageRemoving(t *testing.T) {
kubeClient := setup()
dc := NewController(kubeClient, nodeID, nil, new(events.Recorder), testLogger)
Expand Down
3 changes: 2 additions & 1 deletion pkg/mocks/drivemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"google.golang.org/grpc/status"

api "github.com/dell/csi-baremetal/api/generated/v1"
apiV1 "github.com/dell/csi-baremetal/api/v1"
)

// SmartInfo is a structure to represent basic Smart metrics
Expand Down Expand Up @@ -101,7 +102,7 @@ func (m *MockDriveMgrClient) GetDrivesList(ctx context.Context, in *api.DrivesRe

// Locate is a stub for Locate DriveManager's method
func (m *MockDriveMgrClient) Locate(ctx context.Context, in *api.DriveLocateRequest, opts ...grpc.CallOption) (*api.DriveLocateResponse, error) {
return nil, status.Error(codes.Unimplemented, "method Locate not implemented in MockDriveMgrClient")
return &api.DriveLocateResponse{Status: apiV1.LocateStatusOn}, nil
}

// LocateNode is a stub for LocateNode DriveManager's method
Expand Down

0 comments on commit bd2fe18

Please sign in to comment.