From ca16c5e7472acf32dd0d54b6dab94b36450299c1 Mon Sep 17 00:00:00 2001 From: is005q Date: Thu, 14 Nov 2019 15:51:23 +0200 Subject: [PATCH] [RICPLT-2537] Handle Resource Status Response | Add some fixes to request handler and UT Change-Id: Id1cd582132c094eee96b9d4c246839f3a73ec886 Signed-off-by: is005q --- ...esource_status_initiate_notification_handler.go | 31 ++---- ...ce_status_initiate_notification_handler_test.go | 97 +++++++++---------- .../resource_status_response_handler.go | 32 ++++++- .../resource_status_response_handler_test.go | 105 +++++++++++++++------ RSM/mocks/resource_status_initiate_manager_mock.go | 32 ------- .../message_handler_provider.go | 2 +- RSM/services/resource_status_service.go | 5 + RSM/services/resource_status_service_test.go | 55 +++++++---- RSM/services/rnib_data_service.go | 13 ++- 9 files changed, 214 insertions(+), 158 deletions(-) delete mode 100644 RSM/mocks/resource_status_initiate_manager_mock.go diff --git a/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler.go b/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler.go index 68d5298..9f6bf43 100644 --- a/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler.go +++ b/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler.go @@ -63,15 +63,7 @@ func (h ResourceStatusInitiateNotificationHandler) UnmarshalResourceStatusPayloa func (h ResourceStatusInitiateNotificationHandler) SaveRsmRanInfoStopTrue(inventoryName string) { rsmRanInfo := models.NewRsmRanInfo(inventoryName, 0, 0, enums.Stop, true) - err := h.rnibDataService.SaveRsmRanInfo(rsmRanInfo) - - if err != nil { - h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.SaveRsmRanInfoStopTrue - RAN name: %s - Failed saving RSM data", inventoryName) - return - } - - h.logger.Infof("#ResourceStatusInitiateNotificationHandler.SaveRsmRanInfoStopTrue - RAN name: %s - Successfully saved RSM data", inventoryName) - + _ = h.rnibDataService.SaveRsmRanInfo(rsmRanInfo) } func (h ResourceStatusInitiateNotificationHandler) Handle(request *models.RmrRequest) { @@ -89,31 +81,27 @@ func (h ResourceStatusInitiateNotificationHandler) Handle(request *models.RmrReq return } - nodeb, err := h.rnibDataService.GetNodeb(inventoryName) + config, err := h.rnibDataService.GetRsmGeneralConfiguration() if err != nil { - h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Error fetching RAN from rNib: %v", inventoryName, err) return } - nodebConnectionStatus := nodeb.GetConnectionStatus() - - if nodebConnectionStatus != entities.ConnectionStatus_CONNECTED { - h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - RAN's connection status isn't CONNECTED", inventoryName) - //h.SaveRsmRanInfoStopTrue(inventoryName) + if !config.EnableResourceStatus { + h.SaveRsmRanInfoStopTrue(inventoryName) return } - config, err := h.rnibDataService.GetRsmGeneralConfiguration() + nodeb, err := h.rnibDataService.GetNodeb(inventoryName) if err != nil { - h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Failed retrieving RSM general configuration", inventoryName) return } - h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Successfully retrieved RSM general configuration", inventoryName) + nodebConnectionStatus := nodeb.GetConnectionStatus() - if !config.EnableResourceStatus { + if nodebConnectionStatus != entities.ConnectionStatus_CONNECTED { + h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - RAN's connection status isn't CONNECTED", inventoryName) h.SaveRsmRanInfoStopTrue(inventoryName) return } @@ -122,12 +110,9 @@ func (h ResourceStatusInitiateNotificationHandler) Handle(request *models.RmrReq err = h.rnibDataService.SaveRsmRanInfo(rsmRanInfo) if err != nil { - h.logger.Errorf("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Failed saving RSM data", inventoryName) return } - h.logger.Infof("#ResourceStatusInitiateNotificationHandler.Handle - RAN name: %s - Successfully saved RSM data", inventoryName) - err = h.resourceStatusService.BuildAndSendInitiateRequest(nodeb, config, rsmRanInfo.Enb1MeasurementId) if err != nil { diff --git a/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go b/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go index ddc0474..e9c039b 100644 --- a/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go +++ b/RSM/handlers/rmrmsghandlers/resource_status_initiate_notification_handler_test.go @@ -118,125 +118,126 @@ func TestHandleGnbNode(t *testing.T) { resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } -func TestGetNodebFailure(t *testing.T) { - h, rnibReaderMock, resourceStatusServiceMock, _, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected") - var nodebInfo *entities.NodebInfo - +func TestGetRsmGeneralConfigurationFailure(t *testing.T) { + h, _, resourceStatusServiceMock, _, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") + var rgc models.RsmGeneralConfiguration + rsmReaderMock.On("GetRsmGeneralConfiguration").Return(&rgc, common.NewInternalError(errors.New("Error"))) payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" payload := []byte(payloadStr) rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} - - rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, common.NewInternalError(errors.New("Error"))) resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) + rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } -func TestInvalidConnectionStatus(t *testing.T) { - h, rnibReaderMock, resourceStatusServiceMock, _/*rsmWriterMock*/, _ := initRanConnectedNotificationHandlerTest(t, "RanConnected") +func TestEnableResourceStatusFalse(t *testing.T) { + h, _, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") var err error - rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}, err) - //rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true} - //rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err) + rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(false), err) + rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true} + rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err) payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" payload := []byte(payloadStr) rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) - //rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1) + rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") + rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1) resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } -func TestGetRsmGeneralConfigurationFailure(t *testing.T) { - h, rnibReaderMock, resourceStatusServiceMock, _, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") +func TestEnableResourceStatusFalseSaveRsmRanInfoFailure(t *testing.T) { + h, _, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") var err error - rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err) - var rgc models.RsmGeneralConfiguration - rsmReaderMock.On("GetRsmGeneralConfiguration").Return(&rgc, common.NewInternalError(errors.New("Error"))) + rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(false), err) + rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true} + rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(common.NewInternalError(errors.New("Error"))) + payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" payload := []byte(payloadStr) rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") + rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1) resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } -func TestEnableResourceStatusFalse(t *testing.T) { - h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") - var err error - rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err) - rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(false), err) - rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true} - rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err) +func TestGetNodebFailure(t *testing.T) { + h, rnibReaderMock, resourceStatusServiceMock, _, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" payload := []byte(payloadStr) rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} + + var err error + rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(true), err) + + var nodebInfo *entities.NodebInfo + rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, common.NewInternalError(errors.New("Error"))) resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") - rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1) + rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } -func TestEnableResourceStatusFalseRsmRanInfoFailure(t *testing.T) { +func TestInvalidConnectionStatus(t *testing.T) { h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") var err error - rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err) - rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(false), err) + rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(true), err) + rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}, err) rsmRanInfo := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true} - rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(common.NewInternalError(errors.New("Error"))) + rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err) payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" payload := []byte(payloadStr) rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") + rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1) resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } - func TestEnableResourceStatusTrueSaveRsmRanInfoFailure(t *testing.T) { h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") - var err error - rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err) - rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(true), err) - rsmRanInfo := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false} - rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(common.NewInternalError(errors.New("Error"))) payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" payload := []byte(payloadStr) rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} + + var err error + rsmReaderMock.On("GetRsmGeneralConfiguration").Return(getRsmGeneralConfiguration(true), err) + rnibReaderMock.On("GetNodeb", RanName).Return(&entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED}, err) + rsmRanInfo := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false} + rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(common.NewInternalError(errors.New("Error"))) resourceStatusServiceMock.On("BuildAndSendInitiateRequest", mock.AnythingOfType("*entities.NodebInfo"), mock.AnythingOfType("*models.RsmGeneralConfiguration"), enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") + rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 1) resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 0) } func TestBuildAndSendSuccess(t *testing.T) { h, rnibReaderMock, resourceStatusServiceMock, rsmWriterMock, rsmReaderMock := initRanConnectedNotificationHandlerTest(t, "RanConnected") + + payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" + payload := []byte(payloadStr) + rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} + var err error - nodebInfo := &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED} rgc := getRsmGeneralConfiguration(true) - rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, err) rsmReaderMock.On("GetRsmGeneralConfiguration").Return(rgc, err) + nodebInfo := &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED} + rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, err) rsmRanInfo := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false} rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfo).Return(err) - payloadStr := "{\"nodeType\":1, \"messageDirection\":1}" - payload := []byte(payloadStr) - rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} resourceStatusServiceMock.On("BuildAndSendInitiateRequest", nodebInfo, rgc, enums.Enb1MeasurementId).Return(nil) h.Handle(rmrReq) rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) @@ -250,8 +251,8 @@ func TestBuildAndSendError(t *testing.T) { var err error nodebInfo := &entities.NodebInfo{ConnectionStatus: entities.ConnectionStatus_CONNECTED} rgc := getRsmGeneralConfiguration(true) - rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, err) rsmReaderMock.On("GetRsmGeneralConfiguration").Return(rgc, err) + rnibReaderMock.On("GetNodeb", RanName).Return(nodebInfo, err) rsmRanInfoStart := models.RsmRanInfo{RanName, enums.Enb1MeasurementId, 0, enums.Start, false} rsmWriterMock.On("SaveRsmRanInfo", &rsmRanInfoStart).Return(err) rsmRanInfoStop := models.RsmRanInfo{RanName, 0, 0, enums.Stop, true} @@ -261,8 +262,8 @@ func TestBuildAndSendError(t *testing.T) { rmrReq := &models.RmrRequest{RanName: RanName, Payload: payload, Len: len(payload), StartTime: time.Now()} resourceStatusServiceMock.On("BuildAndSendInitiateRequest", nodebInfo, rgc, enums.Enb1MeasurementId).Return(common.NewInternalError(errors.New("Error"))) h.Handle(rmrReq) - rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) rsmReaderMock.AssertCalled(t, "GetRsmGeneralConfiguration") + rnibReaderMock.AssertCalled(t, "GetNodeb", RanName) resourceStatusServiceMock.AssertNumberOfCalls(t, "BuildAndSendInitiateRequest", 1) rsmWriterMock.AssertNumberOfCalls(t, "SaveRsmRanInfo", 2) } diff --git a/RSM/handlers/rmrmsghandlers/resource_status_response_handler.go b/RSM/handlers/rmrmsghandlers/resource_status_response_handler.go index a0d9ab1..e9ff602 100644 --- a/RSM/handlers/rmrmsghandlers/resource_status_response_handler.go +++ b/RSM/handlers/rmrmsghandlers/resource_status_response_handler.go @@ -22,17 +22,20 @@ import ( "rsm/e2pdus" "rsm/logger" "rsm/models" + "rsm/services" ) type ResourceStatusResponseHandler struct { - logger *logger.Logger - converter converters.IResourceStatusResponseConverter + logger *logger.Logger + rnibDataService services.RNibDataService + converter converters.IResourceStatusResponseConverter } -func NewResourceStatusResponseHandler(logger *logger.Logger, converter converters.IResourceStatusResponseConverter) ResourceStatusResponseHandler { +func NewResourceStatusResponseHandler(logger *logger.Logger, converter converters.IResourceStatusResponseConverter, rnibDataService services.RNibDataService) ResourceStatusResponseHandler { return ResourceStatusResponseHandler{ - logger: logger, - converter: converter, + logger: logger, + converter: converter, + rnibDataService: rnibDataService, } } @@ -64,4 +67,23 @@ func (h ResourceStatusResponseHandler) Handle(request *models.RmrRequest) { request.RanName, response.ENB1_Measurement_ID, response.ENB2_Measurement_ID) + + rsmRanInfo, err := h.rnibDataService.GetRsmRanInfo(request.RanName) + + if err != nil { + h.logger.Errorf("#ResourceStatusResponseHandler.Handle - RAN name: %s - Failed fetching RsmRanInfo", request.RanName) + return + } + + rsmRanInfo.Enb2MeasurementId = response.ENB2_Measurement_ID + rsmRanInfo.ActionStatus = true + + err = h.rnibDataService.SaveRsmRanInfo(rsmRanInfo) + + if err != nil { + h.logger.Errorf("#ResourceStatusResponseHandler.Handle - RAN name: %s - Failed saving RsmRanInfo", request.RanName) + return + } + + h.logger.Infof("#ResourceStatusResponseHandler.Handle - RAN name: %s - Successfully updated RsmRanInfo", request.RanName) } diff --git a/RSM/handlers/rmrmsghandlers/resource_status_response_handler_test.go b/RSM/handlers/rmrmsghandlers/resource_status_response_handler_test.go index ad8a0dc..2739be6 100644 --- a/RSM/handlers/rmrmsghandlers/resource_status_response_handler_test.go +++ b/RSM/handlers/rmrmsghandlers/resource_status_response_handler_test.go @@ -19,48 +19,66 @@ package rmrmsghandlers import ( "fmt" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" + "github.com/pkg/errors" + "rsm/configuration" "rsm/e2pdus" + "rsm/enums" "rsm/logger" "rsm/mocks" "rsm/models" + "rsm/services" "testing" "time" ) -// Verify UnpackX2apPduAsString() and Convert() are called -func TestResourceStatusResponseHandler(t *testing.T) { +func initResourceStatusResponseHandlerTest(t *testing.T) (*mocks.ResourceStatusResponseConverterMock, ResourceStatusResponseHandler, *mocks.RsmReaderMock, *mocks.RsmWriterMock) { logger, err := logger.InitLogger(logger.DebugLevel) if err != nil { t.Errorf("#... - failed to initialize logger, error: %s", err) } + + config, err := configuration.ParseConfiguration() + if err != nil { + t.Errorf("#... - failed to parse configuration error: %s", err) + } + + converterMock := &mocks.ResourceStatusResponseConverterMock{} + + rnibReaderMock := &mocks.RnibReaderMock{} + rsmReaderMock := &mocks.RsmReaderMock{} + rsmWriterMock := &mocks.RsmWriterMock{} + + rnibDataService := services.NewRnibDataService(logger, config, rnibReaderMock, rsmReaderMock, rsmWriterMock) + h := NewResourceStatusResponseHandler(logger, converterMock, rnibDataService) + + return converterMock, h, rsmReaderMock, rsmWriterMock + +} + +// Verify UnpackX2apPduAsString() and Convert() are called +func TestResourceStatusResponseHandler(t *testing.T) { + converterMock, h, _, _ := initResourceStatusResponseHandlerTest(t) + payload := []byte("aaa") req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)} - converterMock := mocks.ResourceStatusResponseConverterMock{} converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil) converterMock.On("Convert", req.Payload).Return((*models.ResourceStatusResponse)(nil), fmt.Errorf("error")) - h := NewResourceStatusResponseHandler(logger, &converterMock) h.Handle(&req) - converterMock.AssertNumberOfCalls(t, "UnpackX2apPduAsString", 1) converterMock.AssertNumberOfCalls(t, "Convert", 1) } -func TestResourceStatusResponseHandlerError(t *testing.T) { - logger, err := logger.InitLogger(logger.DebugLevel) - if err != nil { - t.Errorf("#... - failed to initialize logger, error: %s", err) - } +func TestResourceStatusResponseHandlerConvertError(t *testing.T) { + converterMock, h, _, _ := initResourceStatusResponseHandlerTest(t) + payload := []byte("aaa") req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)} - converterMock := mocks.ResourceStatusResponseConverterMock{} - - err = fmt.Errorf("error") + err := fmt.Errorf("error") var payloadAsString string converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(payloadAsString, err) converterMock.On("Convert", req.Payload).Return((*models.ResourceStatusResponse)(nil), fmt.Errorf("error")) - h := NewResourceStatusResponseHandler(logger, &converterMock) - h.Handle(&req) converterMock.AssertNumberOfCalls(t, "UnpackX2apPduAsString", 1) @@ -68,39 +86,66 @@ func TestResourceStatusResponseHandlerError(t *testing.T) { } func TestResourceStatusResponseHandlerEnb2Mid0(t *testing.T) { - logger, err := logger.InitLogger(logger.DebugLevel) - if err != nil { - t.Errorf("#... - failed to initialize logger, error: %s", err) - } + converterMock, h, _, _ := initResourceStatusResponseHandlerTest(t) + payload := []byte("aaa") req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)} response := &models.ResourceStatusResponse{} - converterMock := mocks.ResourceStatusResponseConverterMock{} converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil) converterMock.On("Convert", req.Payload).Return(response, nil) - h := NewResourceStatusResponseHandler(logger, &converterMock) - h.Handle(&req) converterMock.AssertNumberOfCalls(t, "UnpackX2apPduAsString", 1) converterMock.AssertNumberOfCalls(t, "Convert", 1) } -func TestResourceStatusResponseHandlerWithMid(t *testing.T) { - logger, err := logger.InitLogger(logger.DebugLevel) - if err != nil { - t.Errorf("#... - failed to initialize logger, error: %s", err) - } +func TestResourceStatusResponseHandlerWithMidGetRsmRanInfoFailure(t *testing.T) { + converterMock, h, rsmReaderMock, rsmWriterMock := initResourceStatusResponseHandlerTest(t) payload := []byte("aaa") - req := models.RmrRequest{RanName: "test", StartTime: time.Now(), Payload: payload, Len: len(payload)} + req := models.RmrRequest{RanName: RanName, StartTime: time.Now(), Payload: payload, Len: len(payload)} response := &models.ResourceStatusResponse{ENB1_Measurement_ID: 1, ENB2_Measurement_ID: 2} - converterMock := mocks.ResourceStatusResponseConverterMock{} converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil) converterMock.On("Convert", req.Payload).Return(response, nil) - h := NewResourceStatusResponseHandler(logger, &converterMock) + rsmReaderMock.On("GetRsmRanInfo", RanName).Return(&models.RsmRanInfo{}, common.NewInternalError(errors.New("Error"))) + h.Handle(&req) + converterMock.AssertNumberOfCalls(t, "UnpackX2apPduAsString", 1) + converterMock.AssertNumberOfCalls(t, "Convert", 1) + rsmReaderMock.AssertCalled(t, "GetRsmRanInfo", RanName) + rsmWriterMock.AssertNotCalled(t, "SaveRsmRanInfo") +} +func TestResourceStatusResponseHandlerWithMidUpdateFailure(t *testing.T) { + converterMock, h, rsmReaderMock, rsmWriterMock := initResourceStatusResponseHandlerTest(t) + payload := []byte("aaa") + req := models.RmrRequest{RanName: RanName, StartTime: time.Now(), Payload: payload, Len: len(payload)} + response := &models.ResourceStatusResponse{ENB1_Measurement_ID: 1, ENB2_Measurement_ID: 2} + converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil) + converterMock.On("Convert", req.Payload).Return(response, nil) + rsmRanInfoBefore := models.NewRsmRanInfo(RanName, enums.Enb1MeasurementId, 0, enums.Start, false) + rsmReaderMock.On("GetRsmRanInfo", RanName).Return(rsmRanInfoBefore, nil) + updatedRsmRanInfo := models.NewRsmRanInfo(RanName, enums.Enb1MeasurementId, response.ENB2_Measurement_ID, enums.Start, true) + rsmWriterMock.On("SaveRsmRanInfo", rsmRanInfoBefore).Return(common.NewInternalError(errors.New("Error"))) h.Handle(&req) + converterMock.AssertNumberOfCalls(t, "UnpackX2apPduAsString", 1) + converterMock.AssertNumberOfCalls(t, "Convert", 1) + rsmReaderMock.AssertCalled(t, "GetRsmRanInfo", RanName) + rsmWriterMock.AssertCalled(t, "SaveRsmRanInfo", updatedRsmRanInfo) +} +func TestResourceStatusResponseHandlerWithMidSuccessfulUpdate(t *testing.T) { + converterMock, h, rsmReaderMock, rsmWriterMock := initResourceStatusResponseHandlerTest(t) + payload := []byte("aaa") + req := models.RmrRequest{RanName: RanName, StartTime: time.Now(), Payload: payload, Len: len(payload)} + response := &models.ResourceStatusResponse{ENB1_Measurement_ID: 1, ENB2_Measurement_ID: 2} + converterMock.On("UnpackX2apPduAsString", req.Payload, e2pdus.MaxAsn1CodecMessageBufferSize).Return(string(payload), nil) + converterMock.On("Convert", req.Payload).Return(response, nil) + rsmRanInfoBefore := models.NewRsmRanInfo(RanName, enums.Enb1MeasurementId, 0, enums.Start, false) + rsmReaderMock.On("GetRsmRanInfo", RanName).Return(rsmRanInfoBefore, nil) + updatedRsmRanInfo := models.NewRsmRanInfo(RanName, enums.Enb1MeasurementId, response.ENB2_Measurement_ID, enums.Start, true) + rsmWriterMock.On("SaveRsmRanInfo", rsmRanInfoBefore).Return(nil) + h.Handle(&req) converterMock.AssertNumberOfCalls(t, "UnpackX2apPduAsString", 1) converterMock.AssertNumberOfCalls(t, "Convert", 1) + rsmReaderMock.AssertCalled(t, "GetRsmRanInfo", RanName) + rsmWriterMock.AssertCalled(t, "SaveRsmRanInfo", updatedRsmRanInfo /*&updatedRsmRanInfo*/) } diff --git a/RSM/mocks/resource_status_initiate_manager_mock.go b/RSM/mocks/resource_status_initiate_manager_mock.go deleted file mode 100644 index 269353b..0000000 --- a/RSM/mocks/resource_status_initiate_manager_mock.go +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright 2019 AT&T Intellectual Property -// Copyright 2019 Nokia -// -// 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 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -package mocks - -import ( - "github.com/stretchr/testify/mock" - "rsm/e2pdus" -) - -type ResourceStatusInitiateManagerMock struct { - mock.Mock -} - -func (m *ResourceStatusInitiateManagerMock) Execute(inventoryName string, resourceStatusInitiateRequestParams *e2pdus.ResourceStatusRequestData) error { - args := m.Called(inventoryName, resourceStatusInitiateRequestParams) - return args.Error(0) -} diff --git a/RSM/providers/rmrmsghandlerprovider/message_handler_provider.go b/RSM/providers/rmrmsghandlerprovider/message_handler_provider.go index ca87c0a..4da9731 100644 --- a/RSM/providers/rmrmsghandlerprovider/message_handler_provider.go +++ b/RSM/providers/rmrmsghandlerprovider/message_handler_provider.go @@ -49,7 +49,7 @@ func initMessageHandlersMap(logger *logger.Logger, config *configuration.Configu rmrcgo.RanConnected: rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, rnibDataService, resourceStatusService, RanConnected), rmrcgo.RanRestarted: rmrmsghandlers.NewResourceStatusInitiateNotificationHandler(logger, rnibDataService, resourceStatusService, RanRestarted), rmrcgo.RicResStatusFailure: rmrmsghandlers.NewResourceStatusFailureHandler(logger, rsFailureConverter), - rmrcgo.RicResStatusResp: rmrmsghandlers.NewResourceStatusResponseHandler(logger, rsConverter), + rmrcgo.RicResStatusResp: rmrmsghandlers.NewResourceStatusResponseHandler(logger, rsConverter, rnibDataService), } } diff --git a/RSM/services/resource_status_service.go b/RSM/services/resource_status_service.go index e0bc10c..1430ffa 100644 --- a/RSM/services/resource_status_service.go +++ b/RSM/services/resource_status_service.go @@ -78,6 +78,11 @@ func (m *ResourceStatusService) extractCellIdList(nodeb *entities.NodebInfo) ([] cells := enb.Enb.ServedCells + if len(cells) == 0 { + m.logger.Errorf("#ResourceStatusService.extractCellIdList - Empty cell list for RAN %s", nodeb.RanName) + return []string{}, fmt.Errorf("empty cell list for RAN %s", nodeb.RanName) + } + cellIdList := make([]string, len(cells)) for index, cellInfo := range cells { cellIdList[index] = cellInfo.CellId diff --git a/RSM/services/resource_status_service_test.go b/RSM/services/resource_status_service_test.go index 12f756a..cb017d0 100644 --- a/RSM/services/resource_status_service_test.go +++ b/RSM/services/resource_status_service_test.go @@ -88,56 +88,58 @@ func TestOneCellSuccess(t *testing.T) { rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf) } -func TestOneCellSendFailure(t *testing.T) { - cellId := "02f829:0007ab00" +func TestTwoCellsSuccess(t *testing.T) { + cellId1 := "02f829:0007ab00" + cellId2 := "02f829:0007ab50" rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t) - xaction := []byte(RanName) - var err error nodebInfo := &entities.NodebInfo{ RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, Configuration: &entities.NodebInfo_Enb{ Enb: &entities.Enb{ - ServedCells: []*entities.ServedCellInfo{{CellId: cellId}}, + ServedCells: []*entities.ServedCellInfo{{CellId: cellId1}, {CellId: cellId2}}, }, }, } var expectedPayload []byte - _, _ = fmt.Sscanf(NodebOneCellPackedExample, "%x", &expectedPayload) + _, _ = fmt.Sscanf(NodebTwoCellsPackedExample, "%x", &expectedPayload) expectedMbuf := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload), RanName, &expectedPayload, &xaction) - rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, rsmerrors.NewRmrError()) - err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, 1) - assert.NotNil(t, err) + var err error + rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, err) + err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId) + assert.Nil(t, err) rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf) } -func TestTwoCellsSuccess(t *testing.T) { - cellId1 := "02f829:0007ab00" - cellId2 := "02f829:0007ab50" +func TestOneCellSendFailure(t *testing.T) { + cellId := "02f829:0007ab00" rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t) + xaction := []byte(RanName) + var err error nodebInfo := &entities.NodebInfo{ RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, Configuration: &entities.NodebInfo_Enb{ Enb: &entities.Enb{ - ServedCells: []*entities.ServedCellInfo{{CellId: cellId1}, {CellId: cellId2}}, + ServedCells: []*entities.ServedCellInfo{{CellId: cellId}}, }, }, } var expectedPayload []byte - _, _ = fmt.Sscanf(NodebTwoCellsPackedExample, "%x", &expectedPayload) + _, _ = fmt.Sscanf(NodebOneCellPackedExample, "%x", &expectedPayload) expectedMbuf := rmrcgo.NewMBuf(rmrcgo.RicResStatusReq, len(expectedPayload), RanName, &expectedPayload, &xaction) - var err error - rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, err) - err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId) - assert.Nil(t, err) + rmrMessengerMock.On("SendMsg", expectedMbuf).Return(&rmrcgo.MBuf{}, rsmerrors.NewRmrError()) + err = resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, 1) + assert.NotNil(t, err) rmrMessengerMock.AssertCalled(t, "SendMsg", expectedMbuf) } + + func TestNodebConfigurationFailure(t *testing.T) { rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t) nodebInfo := &entities.NodebInfo{ @@ -150,6 +152,23 @@ func TestNodebConfigurationFailure(t *testing.T) { rmrMessengerMock.AssertNotCalled(t, "SendMsg") } +func TestNodebEmptyCellList(t *testing.T) { + rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t) + nodebInfo := &entities.NodebInfo{ + RanName: RanName, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + Configuration: &entities.NodebInfo_Enb{ + Enb: &entities.Enb{ + ServedCells: []*entities.ServedCellInfo{}, + }, + }, + } + + err := resourceStatusService.BuildAndSendInitiateRequest(nodebInfo, rsmGeneralConfiguration, enums.Enb1MeasurementId) + assert.NotNil(t, err) + rmrMessengerMock.AssertNotCalled(t, "SendMsg") +} + func TestPackFailure(t *testing.T) { rmrMessengerMock, rsmGeneralConfiguration, resourceStatusService := initResourceStatusServiceTest(t) nodebInfo := &entities.NodebInfo{ diff --git a/RSM/services/rnib_data_service.go b/RSM/services/rnib_data_service.go index 95fb1a9..44e9024 100644 --- a/RSM/services/rnib_data_service.go +++ b/RSM/services/rnib_data_service.go @@ -68,6 +68,10 @@ func (w *rNibDataService) GetRsmGeneralConfiguration() (*models.RsmGeneralConfig return }) + if err != nil { + w.logger.Infof("#RnibDataService.GetRsmGeneralConfiguration - Configuration: %+v", rsmGeneralConfiguration) + } + return rsmGeneralConfiguration, err } @@ -81,11 +85,17 @@ func (w *rNibDataService) GetRsmRanInfo(ranName string) (*models.RsmRanInfo, err return }) + if err != nil { + w.logger.Infof("#RnibDataService.GetRsmRanInfo - RsmRanInfo: %+v", ranName) + } + + + return rsmData, err } func (w *rNibDataService) SaveRsmRanInfo(rsmRanInfo *models.RsmRanInfo) error { - w.logger.Infof("#RnibDataService.SaveRsmRanInfo - RAN name: %s", rsmRanInfo.RanName) + w.logger.Infof("#RnibDataService.SaveRsmRanInfo - RsmRanInfo: %+v", rsmRanInfo) err := w.retry("SaveRsmRanInfo", func() (err error) { err = w.rsmWriter.SaveRsmRanInfo(rsmRanInfo) @@ -139,6 +149,7 @@ func (w *rNibDataService) retry(rnibFunc string, f func() error) (err error) { return } if !isRnibConnectionError(err) { + w.logger.Errorf("#RnibDataService.retry - error in %s: %s", rnibFunc, err) return err } if i >= attempts { -- 2.16.6