From 08bbf91d9f5afd6ecd6eeb9bcc8c160b8242d1ec Mon Sep 17 00:00:00 2001 From: idanshal Date: Mon, 20 Apr 2020 17:11:33 +0300 Subject: [PATCH] [RIC-298] Add Update GNB impl. Change-Id: I00e9f23306147b1d195937290dba4d5ca679b36b Signed-off-by: idanshal --- E2Manager/container-tag.yaml | 2 +- E2Manager/controllers/nodeb_controller_test.go | 151 +++++++++++++++++---- .../httpmsghandlers/update_gnb_request_handler.go | 31 +++-- E2Manager/mocks/rnibWriterMock.go | 6 +- E2Manager/rNibWriter/rNibWriter.go | 63 ++++++--- E2Manager/rNibWriter/rNibWriter_test.go | 134 ++++++++++++++++-- E2Manager/services/rnib_data_service.go | 12 ++ 7 files changed, 332 insertions(+), 67 deletions(-) diff --git a/E2Manager/container-tag.yaml b/E2Manager/container-tag.yaml index 19f252f..4463713 100644 --- a/E2Manager/container-tag.yaml +++ b/E2Manager/container-tag.yaml @@ -1,4 +1,4 @@ # The Jenkins job requires a tag to build the Docker image. # Global-JJB script assumes this file is in the repo root. --- -tag: 4.4.3 +tag: 4.4.4 diff --git a/E2Manager/controllers/nodeb_controller_test.go b/E2Manager/controllers/nodeb_controller_test.go index 4716e75..4d5e829 100644 --- a/E2Manager/controllers/nodeb_controller_test.go +++ b/E2Manager/controllers/nodeb_controller_test.go @@ -38,6 +38,7 @@ import ( "fmt" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common" "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" + "github.com/golang/protobuf/jsonpb" "github.com/gorilla/mux" "github.com/pkg/errors" "github.com/stretchr/testify/assert" @@ -57,6 +58,7 @@ const ( ValidationFailureJson = "{\"errorCode\":402,\"errorMessage\":\"Validation error\"}" ResourceNotFoundJson = "{\"errorCode\":404,\"errorMessage\":\"Resource not found\"}" RnibErrorJson = "{\"errorCode\":500,\"errorMessage\":\"RNIB error\"}" + InternalErrorJson = "{\"errorCode\":501,\"errorMessage\":\"Internal Server Error. Please try again later\"}" ) var ( @@ -84,8 +86,13 @@ type getNodebInfoResult struct { rnibError error } +type updateGnbCellsParams struct { + err error +} + type controllerUpdateGnbTestContext struct { getNodebInfoResult *getNodebInfoResult + updateGnbCellsParams *updateGnbCellsParams requestBody map[string]interface{} expectedStatusCode int expectedJsonResponse string @@ -268,23 +275,53 @@ func controllerGetNodebIdListTestExecuter(t *testing.T, context *controllerGetNo assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) } -func controllerUpdateGnbTestExecuter(t *testing.T, context *controllerUpdateGnbTestContext) { - controller, readerMock, _, _, _ := setupControllerTest(t) - writer := httptest.NewRecorder() - +func activateControllerUpdateGnbMocks(context *controllerUpdateGnbTestContext, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { if context.getNodebInfoResult != nil { readerMock.On("GetNodeb", RanName).Return(context.getNodebInfoResult.nodebInfo, context.getNodebInfoResult.rnibError) } + if context.updateGnbCellsParams != nil { + updatedNodebInfo := *context.getNodebInfoResult.nodebInfo + gnb := entities.Gnb{} + _ = jsonpb.Unmarshal(getJsonRequestAsBuffer(context.requestBody), &gnb) + updatedNodebInfo.GetGnb().ServedNrCells = gnb.ServedNrCells + writerMock.On("UpdateGnbCells", &updatedNodebInfo, gnb.ServedNrCells).Return(context.updateGnbCellsParams.err) + } +} + +func assertControllerUpdateGnb(t *testing.T, context *controllerUpdateGnbTestContext, writer *httptest.ResponseRecorder, readerMock *mocks.RnibReaderMock, writerMock *mocks.RnibWriterMock) { + assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) + bodyBytes, _ := ioutil.ReadAll(writer.Body) + assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) + readerMock.AssertExpectations(t) + writerMock.AssertExpectations(t) + + if context.getNodebInfoResult != nil { + readerMock.AssertNotCalled(t, "GetNodeb") + } + + if context.updateGnbCellsParams != nil { + writerMock.AssertNotCalled(t, "UpdateGnb") + } +} + +func buildUpdateGnbRequest(context *controllerUpdateGnbTestContext) *http.Request { updateGnbUrl := fmt.Sprintf("/nodeb/%s/update", RanName) requestBody := getJsonRequestAsBuffer(context.requestBody) req, _ := http.NewRequest(http.MethodGet, updateGnbUrl, requestBody) req.Header.Set("Content-Type", "application/json") req = mux.SetURLVars(req, map[string]string{"ranName": RanName}) + return req +} + +func controllerUpdateGnbTestExecuter(t *testing.T, context *controllerUpdateGnbTestContext) { + controller, readerMock, writerMock, _, _ := setupControllerTest(t) + writer := httptest.NewRecorder() + + activateControllerUpdateGnbMocks(context, readerMock, writerMock) + req := buildUpdateGnbRequest(context) controller.UpdateGnb(writer, req) - assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode) - bodyBytes, _ := ioutil.ReadAll(writer.Body) - assert.Equal(t, context.expectedJsonResponse, string(bodyBytes)) + assertControllerUpdateGnb(t, context, writer, readerMock, writerMock) } func TestControllerUpdateGnbEmptyServedNrCells(t *testing.T) { @@ -370,7 +407,7 @@ func TestControllerUpdateGnbMissingNeighbourInfoFddOrTdd(t *testing.T) { "servedNrCells": []interface{}{ map[string]interface{}{ "servedNrCellInformation": buildServedNrCellInformation(""), - "nrNeighbourInfos": []interface{}{ + "nrNeighbourInfos": []interface{}{ nrNeighbourInfo, }, }, @@ -392,7 +429,7 @@ func TestControllerUpdateGnbMissingNrNeighbourInformationRequiredProp(t *testing "servedNrCells": []interface{}{ map[string]interface{}{ "servedNrCellInformation": buildServedNrCellInformation(""), - "nrNeighbourInfos": []interface{}{ + "nrNeighbourInfos": []interface{}{ buildNrNeighbourInformation(v), }, }, @@ -406,34 +443,31 @@ func TestControllerUpdateGnbMissingNrNeighbourInformationRequiredProp(t *testing } } -func TestControllerUpdateGnbValidServedNrCellInformationAndNrNeighbourInfoGetNodebSuccess(t *testing.T) { +func TestControllerUpdateGnbValidServedNrCellInformationGetNodebNotFound(t *testing.T) { context := controllerUpdateGnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ - nodebInfo: &entities.NodebInfo{RanName: RanName, ConnectionStatus: entities.ConnectionStatus_CONNECTED, AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress}, - rnibError: nil, + nodebInfo: nil, + rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), }, requestBody: map[string]interface{}{ "servedNrCells": []interface{}{ map[string]interface{}{ "servedNrCellInformation": buildServedNrCellInformation(""), - "nrNeighbourInfos": []interface{}{ - buildNrNeighbourInformation(""), - }, }, }, }, - expectedStatusCode: http.StatusOK, - expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", + expectedStatusCode: http.StatusNotFound, + expectedJsonResponse: ResourceNotFoundJson, } controllerUpdateGnbTestExecuter(t, &context) } -func TestControllerUpdateGnbValidServedNrCellInformationGetNodebNotFound(t *testing.T) { +func TestControllerUpdateGnbValidServedNrCellInformationGetNodebInternalError(t *testing.T) { context := controllerUpdateGnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ nodebInfo: nil, - rnibError: common.NewResourceNotFoundError("#reader.GetNodeb - Not found Error"), + rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), }, requestBody: map[string]interface{}{ "servedNrCells": []interface{}{ @@ -442,23 +476,61 @@ func TestControllerUpdateGnbValidServedNrCellInformationGetNodebNotFound(t *test }, }, }, - expectedStatusCode: http.StatusNotFound, - expectedJsonResponse: ResourceNotFoundJson, + expectedStatusCode: http.StatusInternalServerError, + expectedJsonResponse: RnibErrorJson, } controllerUpdateGnbTestExecuter(t, &context) } -func TestControllerUpdateGnbValidServedNrCellInformationGetNodebInternalError(t *testing.T) { +func TestControllerUpdateGnbGetNodebSuccessInvalidGnbConfiguration(t *testing.T) { context := controllerUpdateGnbTestContext{ getNodebInfoResult: &getNodebInfoResult{ - nodebInfo: nil, - rnibError: common.NewInternalError(errors.New("#reader.GetNodeb - Internal Error")), + nodebInfo: &entities.NodebInfo{ + RanName: RanName, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, + }, + rnibError: nil, + }, + requestBody: map[string]interface{}{ + "servedNrCells": []interface{}{ + map[string]interface{}{ + "servedNrCellInformation": buildServedNrCellInformation(""), + "nrNeighbourInfos": []interface{}{ + buildNrNeighbourInformation(""), + }, + }, + }, + }, + expectedStatusCode: http.StatusInternalServerError, + expectedJsonResponse: InternalErrorJson, + } + + controllerUpdateGnbTestExecuter(t, &context) +} + +func TestControllerUpdateGnbGetNodebSuccessUpdateGnbCellsFailure(t *testing.T) { + context := controllerUpdateGnbTestContext{ + updateGnbCellsParams: &updateGnbCellsParams{ + err: common.NewInternalError(errors.New("#writer.UpdateGnbCells - Internal Error")), + }, + getNodebInfoResult: &getNodebInfoResult{ + nodebInfo: &entities.NodebInfo{ + RanName: RanName, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, + Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}}, + }, + rnibError: nil, }, requestBody: map[string]interface{}{ "servedNrCells": []interface{}{ map[string]interface{}{ "servedNrCellInformation": buildServedNrCellInformation(""), + "nrNeighbourInfos": []interface{}{ + buildNrNeighbourInformation(""), + }, }, }, }, @@ -469,6 +541,37 @@ func TestControllerUpdateGnbValidServedNrCellInformationGetNodebInternalError(t controllerUpdateGnbTestExecuter(t, &context) } +func TestControllerUpdateGnbSuccess(t *testing.T) { + context := controllerUpdateGnbTestContext{ + updateGnbCellsParams: &updateGnbCellsParams{ + err: nil, + }, + getNodebInfoResult: &getNodebInfoResult{ + nodebInfo: &entities.NodebInfo{ + RanName: RanName, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + AssociatedE2TInstanceAddress: AssociatedE2TInstanceAddress, + Configuration: &entities.NodebInfo_Gnb{Gnb: &entities.Gnb{}}, + }, + rnibError: nil, + }, + requestBody: map[string]interface{}{ + "servedNrCells": []interface{}{ + map[string]interface{}{ + "servedNrCellInformation": buildServedNrCellInformation(""), + "nrNeighbourInfos": []interface{}{ + buildNrNeighbourInformation(""), + }, + }, + }, + }, + expectedStatusCode: http.StatusOK, + expectedJsonResponse: "{\"ranName\":\"test\",\"connectionStatus\":\"CONNECTED\",\"gnb\":{\"servedNrCells\":[{\"servedNrCellInformation\":{\"nrPci\":1,\"cellId\":\"whatever\",\"servedPlmns\":[\"whatever\"],\"nrMode\":\"FDD\",\"choiceNrMode\":{\"fdd\":{}}},\"nrNeighbourInfos\":[{\"nrPci\":1,\"nrCgi\":\"whatever\",\"nrMode\":\"FDD\",\"choiceNrMode\":{\"tdd\":{}}}]}]},\"associatedE2tInstanceAddress\":\"10.0.2.15:38000\"}", + } + + controllerUpdateGnbTestExecuter(t, &context) +} + func getJsonRequestAsBuffer(requestJson map[string]interface{}) *bytes.Buffer { b := new(bytes.Buffer) _ = json.NewEncoder(b).Encode(requestJson) diff --git a/E2Manager/handlers/httpmsghandlers/update_gnb_request_handler.go b/E2Manager/handlers/httpmsghandlers/update_gnb_request_handler.go index 1d12a53..e22925f 100644 --- a/E2Manager/handlers/httpmsghandlers/update_gnb_request_handler.go +++ b/E2Manager/handlers/httpmsghandlers/update_gnb_request_handler.go @@ -68,21 +68,22 @@ func (h *UpdateGnbRequestHandler) Handle(request models.Request) (models.IRespon return nil, e2managererrors.NewResourceNotFoundError() } - //gnb := nodebInfo.GetGnb() - // - //if gnb == nil { - // // TODO: log and return appropriate error - // return nil, e2managererrors.NewRnibDbError() - //} - // - //gnb.ServedNrCells = updateGnbRequest.ServedNrCells - // - //err = h.rNibDataService.UpdateGnbCells(nodebInfo, updateGnbRequest.ServedNrCells) - // - //if err != nil { - // // TODO: handle error - // return nil, err - //} + ranName:= nodebInfo.RanName + gnb := nodebInfo.GetGnb() + + if gnb == nil { + h.logger.Errorf("#UpdateGnbRequestHandler.Handle - RAN name: %s - nodeb missing gnb configuration", ranName) + return nil, e2managererrors.NewInternalError() + } + + gnb.ServedNrCells = updateGnbRequest.ServedNrCells + + err = h.rNibDataService.UpdateGnbCells(nodebInfo, updateGnbRequest.ServedNrCells) + + if err != nil { + h.logger.Errorf("#UpdateGnbRequestHandler.Handle - RAN name: %s - Failed updating GNB cells. Error: %s", ranName, err) + return nil, e2managererrors.NewRnibDbError() + } return models.NewUpdateGnbResponse(nodebInfo), nil } diff --git a/E2Manager/mocks/rnibWriterMock.go b/E2Manager/mocks/rnibWriterMock.go index 9e1070e..8fb5403 100644 --- a/E2Manager/mocks/rnibWriterMock.go +++ b/E2Manager/mocks/rnibWriterMock.go @@ -17,7 +17,6 @@ // This source code is part of the near-RT RIC (RAN Intelligent Controller) // platform project (RICP). - package mocks import ( @@ -82,3 +81,8 @@ func (rnibWriterMock *RnibWriterMock) RemoveE2TInstance(address string) error { return args.Error(0) } + +func (rnibWriterMock *RnibWriterMock) UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error { + args := rnibWriterMock.Called(nodebInfo, servedNrCells) + return args.Error(0) +} diff --git a/E2Manager/rNibWriter/rNibWriter.go b/E2Manager/rNibWriter/rNibWriter.go index a7195de..f9f75bd 100644 --- a/E2Manager/rNibWriter/rNibWriter.go +++ b/E2Manager/rNibWriter/rNibWriter.go @@ -17,7 +17,6 @@ // This source code is part of the near-RT RIC (RAN Intelligent Controller) // platform project (RICP). - package rNibWriter import ( @@ -44,6 +43,7 @@ type RNibWriter interface { SaveE2TInstance(e2tInstance *entities.E2TInstance) error SaveE2TAddresses(addresses []string) error RemoveE2TInstance(e2tAddress string) error + UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error } /* @@ -83,13 +83,13 @@ func (w *rNibWriterInstance) SaveNodeb(nbIdentity *entities.NbIdentity, entity * } if entity.GetEnb() != nil { - pairs, rNibErr = appendEnbCells(nbIdentity, entity.GetEnb().GetServedCells(), pairs) + pairs, rNibErr = appendEnbCells(nbIdentity.InventoryName, entity.GetEnb().GetServedCells(), pairs) if rNibErr != nil { return rNibErr } } if entity.GetGnb() != nil { - pairs, rNibErr = appendGnbCells(nbIdentity, entity.GetGnb().GetServedNrCells(), pairs) + pairs, rNibErr = appendGnbCells(nbIdentity.InventoryName, entity.GetGnb().GetServedNrCells(), pairs) if rNibErr != nil { return rNibErr } @@ -125,15 +125,34 @@ func (w *rNibWriterInstance) SaveNodeb(nbIdentity *entities.NbIdentity, entity * return nil } -/* -UpdateNodebInfo... -*/ -func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error { +func (w *rNibWriterInstance) UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error { + + pairs, err := buildUpdateNodebInfoPairs(nodebInfo) + + if err != nil { + return err + } + + pairs, err = appendGnbCells(nodebInfo.RanName, servedNrCells, pairs) + + if err != nil { + return err + } + + err = w.sdl.Set(pairs) + + if err != nil { + return common.NewInternalError(err) + } + return nil +} + +func buildUpdateNodebInfoPairs(nodebInfo *entities.NodebInfo) ([]interface{}, error) { nodebNameKey, rNibErr := common.ValidateAndBuildNodeBNameKey(nodebInfo.GetRanName()) if rNibErr != nil { - return rNibErr + return []interface{}{}, rNibErr } nodebIdKey, buildNodebIdKeyError := common.ValidateAndBuildNodeBIdKey(nodebInfo.GetNodeType().String(), nodebInfo.GlobalNbId.GetPlmnId(), nodebInfo.GlobalNbId.GetNbId()) @@ -141,16 +160,29 @@ func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) erro data, err := proto.Marshal(nodebInfo) if err != nil { - return common.NewInternalError(err) + return []interface{}{}, common.NewInternalError(err) } - var pairs []interface{} - pairs = append(pairs, nodebNameKey, data) + pairs := []interface{}{nodebNameKey, data} if buildNodebIdKeyError == nil { pairs = append(pairs, nodebIdKey, data) } + return pairs, nil +} + +/* +UpdateNodebInfo... +*/ +func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error { + + pairs, err := buildUpdateNodebInfoPairs(nodebInfo) + + if err != nil { + return err + } + err = w.sdl.Set(pairs) if err != nil { @@ -235,7 +267,6 @@ func (w *rNibWriterInstance) SaveE2TAddresses(addresses []string) error { return nil } - func (w *rNibWriterInstance) RemoveE2TInstance(address string) error { key, rNibErr := common.ValidateAndBuildE2TInstanceKey(address) if rNibErr != nil { @@ -256,7 +287,7 @@ func Close() { //Nothing to do } -func appendEnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedCellInfo, pairs []interface{}) ([]interface{}, error) { +func appendEnbCells(inventoryName string, cells []*entities.ServedCellInfo, pairs []interface{}) ([]interface{}, error) { for _, cell := range cells { cellEntity := entities.Cell{Type: entities.Cell_LTE_CELL, Cell: &entities.Cell_ServedCellInfo{ServedCellInfo: cell}} cellData, err := proto.Marshal(&cellEntity) @@ -268,7 +299,7 @@ func appendEnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedCel return pairs, rNibErr } pairs = append(pairs, key, cellData) - key, rNibErr = common.ValidateAndBuildCellNamePciKey(nbIdentity.InventoryName, cell.GetPci()) + key, rNibErr = common.ValidateAndBuildCellNamePciKey(inventoryName, cell.GetPci()) if rNibErr != nil { return pairs, rNibErr } @@ -277,7 +308,7 @@ func appendEnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedCel return pairs, nil } -func appendGnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedNRCell, pairs []interface{}) ([]interface{}, error) { +func appendGnbCells(inventoryName string, cells []*entities.ServedNRCell, pairs []interface{}) ([]interface{}, error) { for _, cell := range cells { cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: cell}} cellData, err := proto.Marshal(&cellEntity) @@ -289,7 +320,7 @@ func appendGnbCells(nbIdentity *entities.NbIdentity, cells []*entities.ServedNRC return pairs, rNibErr } pairs = append(pairs, key, cellData) - key, rNibErr = common.ValidateAndBuildCellNamePciKey(nbIdentity.InventoryName, cell.GetServedNrCellInformation().GetNrPci()) + key, rNibErr = common.ValidateAndBuildCellNamePciKey(inventoryName, cell.GetServedNrCellInformation().GetNrPci()) if rNibErr != nil { return pairs, rNibErr } diff --git a/E2Manager/rNibWriter/rNibWriter_test.go b/E2Manager/rNibWriter/rNibWriter_test.go index d38d0fe..9306b97 100644 --- a/E2Manager/rNibWriter/rNibWriter_test.go +++ b/E2Manager/rNibWriter/rNibWriter_test.go @@ -17,7 +17,6 @@ // This source code is part of the near-RT RIC (RAN Intelligent Controller) // platform project (RICP). - package rNibWriter import ( @@ -33,26 +32,141 @@ import ( "time" ) +var namespace = "namespace" + func initSdlInstanceMock(namespace string) (w RNibWriter, sdlInstanceMock *mocks.MockSdlInstance) { sdlInstanceMock = new(mocks.MockSdlInstance) w = GetRNibWriter(sdlInstanceMock) return } -var namespace = "namespace" +func generateNodebInfo(inventoryName string, nodeType entities.Node_Type, plmnId string, nbId string) *entities.NodebInfo { + nodebInfo := &entities.NodebInfo{ + RanName: inventoryName, + GlobalNbId: &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId}, + NodeType: nodeType, + ConnectionStatus: entities.ConnectionStatus_CONNECTED, + } + + if nodeType == entities.Node_ENB { + nodebInfo.Configuration = &entities.NodebInfo_Enb{ + Enb: &entities.Enb{}, + } + } else if nodeType == entities.Node_GNB { + nodebInfo.Configuration = &entities.NodebInfo_Gnb{ + Gnb: &entities.Gnb{}, + } + } + + return nodebInfo +} + +func generateServedNrCells(cellIds ...string) []*entities.ServedNRCell { + + servedNrCells := []*entities.ServedNRCell{} + + for _, v := range cellIds { + servedNrCells = append(servedNrCells, &entities.ServedNRCell{ServedNrCellInformation: &entities.ServedNRCellInformation{ + CellId: v, + ChoiceNrMode: &entities.ServedNRCellInformation_ChoiceNRMode{ + Fdd: &entities.ServedNRCellInformation_ChoiceNRMode_FddInfo{ + + }, + }, + NrMode: entities.Nr_FDD, + NrPci: 5, + ServedPlmns: []string{"whatever"}, + }}) + } + + return servedNrCells +} + +func TestUpdateGnbCellsInvalidNodebInfoFailure(t *testing.T) { + w, sdlInstanceMock := initSdlInstanceMock(namespace) + servedNrCells := generateServedNrCells("test1", "test2") + nodebInfo := &entities.NodebInfo{} + sdlInstanceMock.AssertNotCalled(t, "Set") + rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) + assert.IsType(t, &common.ValidationError{}, rNibErr) +} + +func TestUpdateGnbCellsInvalidCellFailure(t *testing.T) { + inventoryName := "name" + plmnId := "02f829" + nbId := "4a952a0a" + w, sdlInstanceMock := initSdlInstanceMock(namespace) + servedNrCells := []*entities.ServedNRCell{{ServedNrCellInformation: &entities.ServedNRCellInformation{}}} + nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) + nodebInfo.GetGnb().ServedNrCells = servedNrCells + sdlInstanceMock.AssertNotCalled(t, "Set") + rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) + assert.IsType(t, &common.ValidationError{}, rNibErr) +} + +func getUpdateGnbCellsSetExpected(t *testing.T, nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) []interface{} { + + nodebInfoData, err := proto.Marshal(nodebInfo) + if err != nil { + t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal NodeB entity. Error: %s", err) + } + + nodebNameKey, _ := common.ValidateAndBuildNodeBNameKey(nodebInfo.RanName) + nodebIdKey, _ := common.ValidateAndBuildNodeBIdKey(nodebInfo.NodeType.String(), nodebInfo.GlobalNbId.PlmnId, nodebInfo.GlobalNbId.NbId) + setExpected := []interface{}{nodebNameKey, nodebInfoData, nodebIdKey, nodebInfoData} + + for _, v := range servedNrCells { + + cellEntity := entities.Cell{Type: entities.Cell_NR_CELL, Cell: &entities.Cell_ServedNrCell{ServedNrCell: v}} + cellData, err := proto.Marshal(&cellEntity) + + if err != nil { + t.Fatalf("#rNibWriter_test.getUpdateGnbCellsSetExpected - Failed to marshal cell entity. Error: %s", err) + } + + nrCellIdKey, _ := common.ValidateAndBuildNrCellIdKey(v.GetServedNrCellInformation().GetCellId()) + cellNamePciKey, _ := common.ValidateAndBuildCellNamePciKey(nodebInfo.RanName, v.GetServedNrCellInformation().GetNrPci()) + setExpected = append(setExpected, nrCellIdKey, cellData, cellNamePciKey, cellData) + } + + return setExpected +} + +func TestUpdateGnbCellsSdlFailure(t *testing.T) { + inventoryName := "name" + plmnId := "02f829" + nbId := "4a952a0a" + w, sdlInstanceMock := initSdlInstanceMock(namespace) + servedNrCells := generateServedNrCells("test1", "test2") + nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) + nodebInfo.GetGnb().ServedNrCells = servedNrCells + setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells) + sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(errors.New("expected error")) + rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) + assert.IsType(t, &common.InternalError{}, rNibErr) +} + +func TestUpdateGnbCellsSuccess(t *testing.T) { + inventoryName := "name" + plmnId := "02f829" + nbId := "4a952a0a" + w, sdlInstanceMock := initSdlInstanceMock(namespace) + servedNrCells := generateServedNrCells("test1", "test2") + nodebInfo := generateNodebInfo(inventoryName, entities.Node_GNB, plmnId, nbId) + nodebInfo.GetGnb().ServedNrCells = servedNrCells + setExpected := getUpdateGnbCellsSetExpected(t, nodebInfo, servedNrCells) + var e error + sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e) + rNibErr := w.UpdateGnbCells(nodebInfo, servedNrCells) + assert.Nil(t, rNibErr) +} func TestUpdateNodebInfoSuccess(t *testing.T) { inventoryName := "name" plmnId := "02f829" nbId := "4a952a0a" w, sdlInstanceMock := initSdlInstanceMock(namespace) - nodebInfo := &entities.NodebInfo{} - nodebInfo.RanName = inventoryName - nodebInfo.GlobalNbId = &entities.GlobalNbId{PlmnId: plmnId, NbId: nbId} - nodebInfo.NodeType = entities.Node_ENB - nodebInfo.ConnectionStatus = 1 - enb := entities.Enb{} - nodebInfo.Configuration = &entities.NodebInfo_Enb{Enb: &enb} + nodebInfo := generateNodebInfo(inventoryName, entities.Node_ENB, plmnId, nbId) data, err := proto.Marshal(nodebInfo) if err != nil { t.Errorf("#rNibWriter_test.TestSaveEnb - Failed to marshal NodeB entity. Error: %v", err) @@ -391,7 +505,7 @@ func generateCellLoadInformation() *entities.CellLoadInformation { } compInformationItem := &entities.CompInformationItem{ - CompHypothesisSets: []*entities.CompHypothesisSet{&entities.CompHypothesisSet{CellId: "789", CompHypothesis: "xxx"}}, + CompHypothesisSets: []*entities.CompHypothesisSet{{CellId: "789", CompHypothesis: "xxx"}}, BenefitMetric: 50, } diff --git a/E2Manager/services/rnib_data_service.go b/E2Manager/services/rnib_data_service.go index 0fb2724..af329af 100644 --- a/E2Manager/services/rnib_data_service.go +++ b/E2Manager/services/rnib_data_service.go @@ -48,6 +48,7 @@ type RNibDataService interface { SaveE2TInstanceNoLogs(e2tInstance *entities.E2TInstance) error GetE2TAddressesNoLogs() ([]string, error) RemoveE2TInstance(e2tAddress string) error + UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error } type rNibDataService struct { @@ -68,6 +69,17 @@ func NewRnibDataService(logger *logger.Logger, config *configuration.Configurati } } +func (w *rNibDataService) UpdateGnbCells(nodebInfo *entities.NodebInfo, servedNrCells []*entities.ServedNRCell) error { + w.logger.Infof("#RnibDataService.UpdateGnbCells - nodebInfo: %s, servedNrCells: %s", nodebInfo, servedNrCells) + + err := w.retry("UpdateGnbCells", func() (err error) { + err = w.rnibWriter.UpdateGnbCells(nodebInfo, servedNrCells) + return + }) + + return err +} + func (w *rNibDataService) UpdateNodebInfo(nodebInfo *entities.NodebInfo) error { w.logger.Infof("#RnibDataService.UpdateNodebInfo - nodebInfo: %s", nodebInfo) -- 2.16.6