X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=E2Manager%2Fhandlers%2Fhttpmsghandlers%2Fhealth_check_handler_test.go;h=4bce41fda32a2f00d0ddb2facf56764e54c50009;hb=refs%2Fchanges%2F43%2F11243%2F3;hp=2c519df69450c3e729fe71f1c5d0cf79514622f9;hpb=fe8d481d7f3e8d4b889ee3dcd995984eeb64cc6e;p=ric-plt%2Fe2mgr.git
diff --git a/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go b/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go
index 2c519df..4bce41f 100644
--- a/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go
+++ b/E2Manager/handlers/httpmsghandlers/health_check_handler_test.go
@@ -19,18 +19,31 @@
package httpmsghandlers
import (
+ "bytes"
"e2mgr/configuration"
"e2mgr/e2managererrors"
"e2mgr/mocks"
"e2mgr/models"
+ "e2mgr/rmrCgo"
"e2mgr/services"
+ "e2mgr/utils"
+ "encoding/xml"
+ "errors"
"gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
- "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/mock"
+ "strings"
"testing"
+ "unsafe"
)
-func setupHealthCheckHandlerTest(t *testing.T) (*HealthCheckRequestHandler, services.RNibDataService, *mocks.RnibReaderMock, *mocks.RanListManagerMock) {
+const (
+ e2tInstanceFullAddress = "10.0.2.15:9999"
+ e2SetupMsgPrefix = e2tInstanceFullAddress + "|"
+ GnbSetupRequestXmlPath = "../../tests/resources/setupRequest/setupRequest_gnb.xml"
+)
+
+func setupHealthCheckHandlerTest(t *testing.T) (*HealthCheckRequestHandler, services.RNibDataService, *mocks.RnibReaderMock, *mocks.RanListManagerMock, *mocks.RmrMessengerMock) {
logger := initLog(t)
config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
@@ -44,45 +57,62 @@ func setupHealthCheckHandlerTest(t *testing.T) (*HealthCheckRequestHandler, serv
rmrSender := getRmrSender(rmrMessengerMock, logger)
handler := NewHealthCheckRequestHandler(logger, rnibDataService, ranListManagerMock, rmrSender)
- return handler, rnibDataService, readerMock, ranListManagerMock
+ return handler, rnibDataService, readerMock, ranListManagerMock, rmrMessengerMock
}
func TestHealthCheckRequestHandlerArguementHasRanNameSuccess(t *testing.T) {
- handler, _, readerMock, _ := setupHealthCheckHandlerTest(t)
-
- nb1 := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_CONNECTED}
+ handler, _, readerMock, ranListManagerMock, rmrMessengerMock := setupHealthCheckHandlerTest(t)
ranNames := []string{"RanName_1"}
- readerMock.On("GetNodeb", "RanName_1").Return(nb1, nil)
+ nb1:= createNbIdentity(t,"RanName_1", entities.ConnectionStatus_CONNECTED)
+ oldnbIdentity := &entities.NbIdentity{InventoryName: nb1.RanName, ConnectionStatus: nb1.ConnectionStatus}
+ newnbIdentity := &entities.NbIdentity{InventoryName: nb1.RanName, ConnectionStatus: nb1.ConnectionStatus}
- _, err := handler.Handle(models.HealthCheckRequest{ranNames})
+ readerMock.On("GetNodeb", nb1.RanName).Return(nb1, nil)
+
+ mbuf:= createRMRMbuf(t, nb1)
+ rmrMessengerMock.On("SendMsg",mbuf,true).Return(mbuf,nil)
+ ranListManagerMock.On("UpdateHealthcheckTimeStampSent",nb1.RanName).Return(oldnbIdentity, newnbIdentity)
+ ranListManagerMock.On("UpdateNbIdentities",nb1.NodeType, []*entities.NbIdentity{oldnbIdentity}, []*entities.NbIdentity{newnbIdentity}).Return(nil)
+ resp, err := handler.Handle(models.HealthCheckRequest{ranNames})
+
+ assert.IsType(t, &models.HealthCheckSuccessResponse{}, resp)
assert.Nil(t, err)
readerMock.AssertExpectations(t)
}
func TestHealthCheckRequestHandlerArguementHasNoRanNameSuccess(t *testing.T) {
- handler, _, readerMock, ranListManagerMock := setupHealthCheckHandlerTest(t)
+ handler, _, readerMock, ranListManagerMock, rmrMessengerMock := setupHealthCheckHandlerTest(t)
nbIdentityList := []*entities.NbIdentity{{InventoryName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_CONNECTED},
{InventoryName: "RanName_2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}}
ranListManagerMock.On("GetNbIdentityList").Return(nbIdentityList)
- nb1 := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_CONNECTED}
- readerMock.On("GetNodeb", "RanName_1").Return(nb1, nil)
+ nb1:= createNbIdentity(t,"RanName_1", entities.ConnectionStatus_CONNECTED)
+ oldnbIdentity := &entities.NbIdentity{InventoryName: nb1.RanName, ConnectionStatus: nb1.ConnectionStatus}
+ newnbIdentity := &entities.NbIdentity{InventoryName: nb1.RanName, ConnectionStatus: nb1.ConnectionStatus}
+
+ readerMock.On("GetNodeb", nb1.RanName).Return(nb1, nil)
+
+ mbuf:= createRMRMbuf(t, nb1)
+ rmrMessengerMock.On("SendMsg",mbuf,true).Return(mbuf,nil)
+ ranListManagerMock.On("UpdateHealthcheckTimeStampSent",nb1.RanName).Return(oldnbIdentity, newnbIdentity)
+ ranListManagerMock.On("UpdateNbIdentities",nb1.NodeType, []*entities.NbIdentity{oldnbIdentity}, []*entities.NbIdentity{newnbIdentity}).Return(nil)
nb2 := &entities.NodebInfo{RanName: "RanName_2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}
readerMock.On("GetNodeb", "RanName_2").Return(nb2, nil)
- _, err := handler.Handle(models.HealthCheckRequest{[]string{}})
+ resp, err := handler.Handle(models.HealthCheckRequest{[]string{}})
assert.Nil(t, err)
+ assert.IsType(t, &models.HealthCheckSuccessResponse{}, resp)
}
func TestHealthCheckRequestHandlerArguementHasNoRanConnectedFailure(t *testing.T) {
- handler, _, readerMock, ranListManagerMock := setupHealthCheckHandlerTest(t)
+ handler, _, readerMock, ranListManagerMock, rmrMessengerMock := setupHealthCheckHandlerTest(t)
nbIdentityList := []*entities.NbIdentity{{InventoryName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED},
{InventoryName: "RanName_2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}}
@@ -91,23 +121,85 @@ func TestHealthCheckRequestHandlerArguementHasNoRanConnectedFailure(t *testing.T
nb1 := &entities.NodebInfo{RanName: "RanName_1", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}
readerMock.On("GetNodeb", "RanName_1").Return(nb1, nil)
- nb2 := &entities.NodebInfo{RanName: "RanName_2", ConnectionStatus: entities.ConnectionStatus_DISCONNECTED}
+ nb2 := &entities.NodebInfo{RanName: "RanName_2", ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}
readerMock.On("GetNodeb", "RanName_2").Return(nb2, nil)
_, err := handler.Handle(models.HealthCheckRequest{[]string{}})
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
+ ranListManagerMock.AssertNotCalled(t,"UpdateHealthcheckTimeStampSent",mock.Anything)
+ ranListManagerMock.AssertNotCalled(t,"UpdateNbIdentities",mock.Anything, mock.Anything, mock.Anything)
assert.IsType(t, &e2managererrors.NoConnectedRanError{}, err)
}
func TestHealthCheckRequestHandlerArguementHasRanNameDBErrorFailure(t *testing.T) {
- handler, _, readerMock, _ := setupHealthCheckHandlerTest(t)
+ handler, _, readerMock, ranListManagerMock, rmrMessengerMock := setupHealthCheckHandlerTest(t)
ranNames := []string{"RanName_1"}
readerMock.On("GetNodeb", "RanName_1").Return(&entities.NodebInfo{}, errors.New("error"))
_, err := handler.Handle(models.HealthCheckRequest{ranNames})
+ rmrMessengerMock.AssertNotCalled(t, "SendMsg", mock.Anything, mock.Anything)
+ ranListManagerMock.AssertNotCalled(t,"UpdateHealthcheckTimeStampSent",mock.Anything)
+ ranListManagerMock.AssertNotCalled(t,"UpdateNbIdentities",mock.Anything, mock.Anything, mock.Anything)
assert.IsType(t, &e2managererrors.RnibDbError{}, err)
readerMock.AssertExpectations(t)
}
+
+func createRMRMbuf(t *testing.T, nodebInfo *entities.NodebInfo) *rmrCgo.MBuf{
+ serviceQuery := models.NewRicServiceQueryMessage(nodebInfo.GetGnb().RanFunctions)
+ payLoad, err := xml.Marshal(&serviceQuery.E2APPDU)
+ payLoad = utils.NormalizeXml(payLoad)
+ tagsToReplace := []string{"reject","ignore","protocolIEs"}
+ payLoad = utils.ReplaceEmptyTagsWithSelfClosing(payLoad, tagsToReplace)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ var xAction []byte
+ var msgSrc unsafe.Pointer
+
+ rmrMessage := models.NewRmrMessage(rmrCgo.RIC_SERVICE_QUERY, nodebInfo.RanName, payLoad, xAction, msgSrc)
+ return rmrCgo.NewMBuf(rmrMessage.MsgType, len(rmrMessage.Payload), rmrMessage.RanName, &rmrMessage.Payload, &rmrMessage.XAction, rmrMessage.GetMsgSrc())
+}
+
+func createNbIdentity(t *testing.T, RanName string, connectionStatus entities.ConnectionStatus) *entities.NodebInfo {
+ xmlgnb := utils.ReadXmlFile(t, GnbSetupRequestXmlPath)
+ payload := append([]byte(e2SetupMsgPrefix), xmlgnb...)
+ pipInd := bytes.IndexByte(payload, '|')
+ setupRequest := &models.E2SetupRequestMessage{}
+ err := xml.Unmarshal(utils.NormalizeXml(payload[pipInd+1:]), &setupRequest.E2APPDU)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ nodeb := &entities.NodebInfo{
+ AssociatedE2TInstanceAddress: e2tInstanceFullAddress,
+ RanName: RanName,
+ SetupFromNetwork: true,
+ NodeType: entities.Node_GNB,
+ ConnectionStatus: connectionStatus,
+ Configuration: &entities.NodebInfo_Gnb{
+ Gnb: &entities.Gnb{
+ GnbType: entities.GnbType_GNB,
+ RanFunctions: setupRequest.ExtractRanFunctionsList(),
+ },
+ },
+ GlobalNbId: &entities.GlobalNbId{
+ PlmnId: setupRequest.GetPlmnId(),
+ NbId: setupRequest.GetNbId(),
+ },
+ }
+ return nodeb
+}
+
+func normalizeXml(payload []byte) []byte {
+ xmlStr := string(payload)
+ normalized := strings.NewReplacer("<", "<", ">", ">",
+ "","","","",
+ "","").Replace(xmlStr)
+ return []byte(normalized)
+}