[RICPLT-1853] Couple of adjustments......... 24/824/1
authoris005q <idan.shalom@intl.att.com>
Wed, 28 Aug 2019 14:51:37 +0000 (17:51 +0300)
committeris005q <idan.shalom@intl.att.com>
Wed, 28 Aug 2019 14:51:49 +0000 (17:51 +0300)
Change-Id: Icf13fd97a4d56d0f5661daabdb0d4601894518e5
Signed-off-by: is005q <idan.shalom@intl.att.com>
E2Manager/handlers/ranLostConnectionHandler_test.go [deleted file]
E2Manager/handlers/ran_lost_connection_handler.go [moved from E2Manager/handlers/ranLostConnectionHandler.go with 81% similarity]
E2Manager/handlers/ran_lost_connection_handler_test.go [new file with mode: 0644]
E2Manager/managers/ran_reconnection_manager.go
E2Manager/managers/ran_reconnection_manager_test.go
E2Manager/managers/ran_setup_manager.go
E2Manager/rNibWriter/rNibWriter.go
E2Manager/rNibWriter/rNibWriter_test.go

diff --git a/E2Manager/handlers/ranLostConnectionHandler_test.go b/E2Manager/handlers/ranLostConnectionHandler_test.go
deleted file mode 100644 (file)
index ea735b2..0000000
+++ /dev/null
@@ -1,221 +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 handlers
-
-import (
-       "e2mgr/logger"
-       "e2mgr/mocks"
-       "e2mgr/models"
-       "e2mgr/sessions"
-       "github.com/pkg/errors"
-       "testing"
-)
-
-func TestLostConnectionHandlerSuccess(t *testing.T) {
-       logger, _ := logger.InitLogger(logger.InfoLevel)
-       ranName := "test"
-       notificationRequest := models.NotificationRequest{RanName: ranName}
-       ranReconnectionManagerMock := &mocks.RanReconnectionManagerMock{}
-       ranReconnectionManagerMock.On("ReconnectRan", ranName).Return(nil)
-       handler := NewRanLostConnectionHandler(ranReconnectionManagerMock)
-       handler.Handle(logger, make(sessions.E2Sessions), &notificationRequest, nil)
-       ranReconnectionManagerMock.AssertCalled(t, "ReconnectRan", ranName)
-}
-
-func TestLostConnectionHandlerFailure(t *testing.T) {
-       logger, _ := logger.InitLogger(logger.InfoLevel)
-       ranName := "test"
-       notificationRequest := models.NotificationRequest{RanName: ranName}
-       ranReconnectionManagerMock := &mocks.RanReconnectionManagerMock{}
-       ranReconnectionManagerMock.On("ReconnectRan", ranName).Return(errors.New("error"))
-       handler := NewRanLostConnectionHandler(ranReconnectionManagerMock)
-       handler.Handle(logger, make(sessions.E2Sessions), &notificationRequest, nil)
-       ranReconnectionManagerMock.AssertCalled(t, "ReconnectRan", ranName)
-}
-
-//
-//func TestHandleUnsolicitedDisconnectionNotConnectedSuccess(t *testing.T){
-//     log, err := logger.InitLogger(logger.DebugLevel)
-//     if err!=nil{
-//             t.Errorf("#sctp_errors_notification_handler_test.TestHandleNoSession - failed to initialize logger, error: %s", err)
-//     }
-//
-//     readerMock :=&mocks.RnibReaderMock{}
-//     rnibReaderProvider := func() reader.RNibReader {
-//             return readerMock
-//     }
-//     writerMock := &mocks.RnibWriterMock{}
-//     rnibWriterProvider := func() rNibWriter.RNibWriter {
-//             return writerMock
-//     }
-//     h := NewRanLostConnectionHandler(rnibReaderProvider,rnibWriterProvider)
-//
-//     e2Sessions := make(sessions.E2Sessions)
-//     transactionId := "1234"
-//     xaction := []byte(fmt.Sprintf("%32s", transactionId+"6"))
-//     e2Sessions[transactionId] = sessions.E2SessionDetails{SessionStart: time.Now()}
-//     payload := []byte("Error")
-//     mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
-//     notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(),
-//             TransactionId: string(xaction)}
-//     var messageChannel chan<- *models.NotificationResponse
-//
-//     nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_DISCONNECTED,}
-//     var rnibErr common.IRNibError
-//     readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
-//     updatedNb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_DISCONNECTED,}
-//     writerMock.On("SaveNodeb", mock.Anything, updatedNb).Return(rnibErr)
-//
-//     h.Handle(log,e2Sessions, &notificationRequest, messageChannel)
-//}
-//
-//func TestHandleUnsolicitedDisconnectionShuttingDownSuccess(t *testing.T){
-//     log, err := logger.InitLogger(logger.DebugLevel)
-//     if err!=nil{
-//             t.Errorf("#sctp_errors_notification_handler_test.TestHandleNoSession - failed to initialize logger, error: %s", err)
-//     }
-//
-//     readerMock :=&mocks.RnibReaderMock{}
-//     rnibReaderProvider := func() reader.RNibReader {
-//             return readerMock
-//     }
-//     writerMock := &mocks.RnibWriterMock{}
-//     rnibWriterProvider := func() rNibWriter.RNibWriter {
-//             return writerMock
-//     }
-//     h := NewRanLostConnectionHandler(rnibReaderProvider,rnibWriterProvider)
-//
-//     e2Sessions := make(sessions.E2Sessions)
-//     transactionId := "1234"
-//     xaction := []byte(fmt.Sprintf("%32s", transactionId+"6"))
-//     e2Sessions[transactionId] = sessions.E2SessionDetails{SessionStart: time.Now()}
-//     payload := []byte("Error")
-//     mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
-//     notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(),
-//             TransactionId: string(xaction)}
-//     var messageChannel chan<- *models.NotificationResponse
-//
-//     nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUTTING_DOWN,}
-//     var rnibErr common.IRNibError
-//     readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
-//     updatedNb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
-//     writerMock.On("SaveNodeb", mock.Anything, updatedNb).Return(rnibErr)
-//
-//     h.Handle(log,e2Sessions, &notificationRequest, messageChannel)
-//}
-//
-//func TestHandleUnsolicitedDisconnectionShutDownSuccess(t *testing.T){
-//     log, err := logger.InitLogger(logger.DebugLevel)
-//     if err!=nil{
-//             t.Errorf("#sctp_errors_notification_handler_test.TestHandleNoSession - failed to initialize logger, error: %s", err)
-//     }
-//
-//     readerMock :=&mocks.RnibReaderMock{}
-//     rnibReaderProvider := func() reader.RNibReader {
-//             return readerMock
-//     }
-//     writerMock := &mocks.RnibWriterMock{}
-//     rnibWriterProvider := func() rNibWriter.RNibWriter {
-//             return writerMock
-//     }
-//     h := NewRanLostConnectionHandler(rnibReaderProvider,rnibWriterProvider)
-//
-//     e2Sessions := make(sessions.E2Sessions)
-//     transactionId := "1234"
-//     xaction := []byte(fmt.Sprintf("%32s", transactionId+"6"))
-//     e2Sessions[transactionId] = sessions.E2SessionDetails{SessionStart: time.Now()}
-//     payload := []byte("Error")
-//     mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
-//     notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(),
-//             TransactionId: string(xaction)}
-//     var messageChannel chan<- *models.NotificationResponse
-//
-//     nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
-//     var rnibErr common.IRNibError
-//     readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
-//     updatedNb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_SHUT_DOWN,}
-//     writerMock.On("SaveNodeb", mock.Anything, updatedNb).Return(rnibErr)
-//
-//     h.Handle(log,e2Sessions, &notificationRequest, messageChannel)
-//}
-//
-//func TestHandleUnsolicitedDisconnectionReaderFailure(t *testing.T){
-//     log, err := logger.InitLogger(logger.DebugLevel)
-//     if err!=nil{
-//             t.Errorf("#sctp_errors_notification_handler_test.TestHandleNoSession - failed to initialize logger, error: %s", err)
-//     }
-//
-//     readerMock :=&mocks.RnibReaderMock{}
-//     rnibReaderProvider := func() reader.RNibReader {
-//             return readerMock
-//     }
-//     writerMock := &mocks.RnibWriterMock{}
-//     rnibWriterProvider := func() rNibWriter.RNibWriter {
-//             return writerMock
-//     }
-//     h := NewRanLostConnectionHandler(rnibReaderProvider,rnibWriterProvider)
-//
-//     e2Sessions := make(sessions.E2Sessions)
-//     transactionId := "1234"
-//     xaction := []byte(fmt.Sprintf("%32s", transactionId+"6"))
-//     e2Sessions[transactionId] = sessions.E2SessionDetails{SessionStart: time.Now()}
-//     payload := []byte("Error")
-//     mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
-//     notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(),
-//             TransactionId: string(xaction)}
-//     var messageChannel chan<- *models.NotificationResponse
-//
-//     var nb *entities.NodebInfo
-//     rnibErr := common.RNibError{}
-//     readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
-//     h.Handle(log,e2Sessions, &notificationRequest, messageChannel)
-//}
-//
-//func TestHandleUnsolicitedDisconnectionWriterFailure(t *testing.T){
-//     log, err := logger.InitLogger(logger.DebugLevel)
-//     if err!=nil{
-//             t.Errorf("#sctp_errors_notification_handler_test.TestHandleNoSession - failed to initialize logger, error: %s", err)
-//     }
-//
-//     readerMock :=&mocks.RnibReaderMock{}
-//     rnibReaderProvider := func() reader.RNibReader {
-//             return readerMock
-//     }
-//     writerMock := &mocks.RnibWriterMock{}
-//     rnibWriterProvider := func() rNibWriter.RNibWriter {
-//             return writerMock
-//     }
-//     h := NewRanLostConnectionHandler(rnibReaderProvider,rnibWriterProvider)
-//
-//     e2Sessions := make(sessions.E2Sessions)
-//     transactionId := "1234"
-//     xaction := []byte(fmt.Sprintf("%32s", transactionId+"6"))
-//     e2Sessions[transactionId] = sessions.E2SessionDetails{SessionStart: time.Now()}
-//     payload := []byte("Error")
-//     mBuf := rmrCgo.NewMBuf(tests.MessageType, len(payload),"RanName", &payload, &xaction)
-//     notificationRequest := models.NotificationRequest{RanName: mBuf.Meid, Len: mBuf.Len, Payload: *mBuf.Payload, StartTime: time.Now(),
-//             TransactionId: string(xaction)}
-//     var messageChannel chan<- *models.NotificationResponse
-//
-//     nb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_CONNECTED,}
-//     var rnibErr common.IRNibError
-//     readerMock.On("GetNodeb", mBuf.Meid).Return(nb, rnibErr)
-//     updatedNb := &entities.NodebInfo{RanName:mBuf.Meid, ConnectionStatus:entities.ConnectionStatus_DISCONNECTED,}
-//     writerMock.On("SaveNodeb", mock.Anything, updatedNb).Return(common.RNibError{})
-//
-//     h.Handle(log,e2Sessions, &notificationRequest, messageChannel)
-//}
@@ -35,9 +35,16 @@ func NewRanLostConnectionHandler(ranReconnectionManager managers.IRanReconnectio
 }
 func (handler RanLostConnectionHandler) Handle(logger *logger.Logger, e2Sessions sessions.E2Sessions, request *models.NotificationRequest, messageChannel chan<- *models.NotificationResponse) {
 
-       logger.Warnf("#RanLostConnectionHandler.Handle - RAN name: %s - Received lost connection notification", request.RanName)
+       ranName := request.TransactionId
 
-       err := handler.ranReconnectionManager.ReconnectRan(request.RanName)
+       // TODO: check with E2T dev why does request.RanName (MEID) does not contain the ran name (in case sim is down)
+       if len(request.RanName) > 0 {
+               ranName = request.RanName
+       }
+
+       logger.Warnf("#RanLostConnectionHandler.Handle - RAN name: %s - Received lost connection notification", ranName)
+
+       err := handler.ranReconnectionManager.ReconnectRan(ranName)
 
        if err != nil {
                logger.Errorf("#RanLostConnectionHandler.Handle - An error occurred while trying to reconnect RAN, %v", err)
diff --git a/E2Manager/handlers/ran_lost_connection_handler_test.go b/E2Manager/handlers/ran_lost_connection_handler_test.go
new file mode 100644 (file)
index 0000000..52b71d8
--- /dev/null
@@ -0,0 +1,48 @@
+////
+//// 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 handlers
+
+import (
+       "e2mgr/logger"
+       "e2mgr/mocks"
+       "e2mgr/models"
+       "e2mgr/sessions"
+       "github.com/pkg/errors"
+       "testing"
+)
+
+func TestLostConnectionHandlerSuccess(t *testing.T) {
+       logger, _ := logger.InitLogger(logger.InfoLevel)
+       ranName := "test"
+       notificationRequest := models.NotificationRequest{RanName: ranName}
+       ranReconnectionManagerMock := &mocks.RanReconnectionManagerMock{}
+       ranReconnectionManagerMock.On("ReconnectRan", ranName).Return(nil)
+       handler := NewRanLostConnectionHandler(ranReconnectionManagerMock)
+       handler.Handle(logger, make(sessions.E2Sessions), &notificationRequest, nil)
+       ranReconnectionManagerMock.AssertCalled(t, "ReconnectRan", ranName)
+}
+
+func TestLostConnectionHandlerFailure(t *testing.T) {
+       logger, _ := logger.InitLogger(logger.InfoLevel)
+       ranName := "test"
+       notificationRequest := models.NotificationRequest{RanName: ranName}
+       ranReconnectionManagerMock := &mocks.RanReconnectionManagerMock{}
+       ranReconnectionManagerMock.On("ReconnectRan", ranName).Return(errors.New("error"))
+       handler := NewRanLostConnectionHandler(ranReconnectionManagerMock)
+       handler.Handle(logger, make(sessions.E2Sessions), &notificationRequest, nil)
+       ranReconnectionManagerMock.AssertCalled(t, "ReconnectRan", ranName)
+}
\ No newline at end of file
index df3467a..ec521a1 100644 (file)
@@ -53,23 +53,23 @@ func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error {
        nodebInfo, rnibErr := m.rnibReaderProvider().GetNodeb(inventoryName)
 
        if rnibErr != nil {
-               m.logger.Errorf("#ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr)
+               m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed fetching RAN from rNib. Error: %v", inventoryName, rnibErr)
                return rnibErr
        }
 
        if !m.canReconnectRan(nodebInfo) {
-               m.logger.Warnf("#ReconnectRan - RAN name: %s - Cannot reconnect RAN", inventoryName)
+               m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN", inventoryName)
                return m.setConnectionStatusOfUnconnectableRan(nodebInfo)
        }
 
        err := m.ranSetupManager.ExecuteSetup(nodebInfo)
 
        if err != nil {
-               m.logger.Errorf("#ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err)
+               m.logger.Errorf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Failed executing setup. Error: %v", inventoryName, err)
                return err
        }
 
-       m.logger.Infof("#ReconnectRan - RAN name: %s - Successfully done executing setup", inventoryName)
+       m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - Successfully done executing setup. RAN's connection attempts: %d", inventoryName, nodebInfo.ConnectionAttempts)
        return nil
 }
 
@@ -80,28 +80,32 @@ func (m *RanReconnectionManager) canReconnectRan(nodebInfo *entities.NodebInfo)
 }
 
 func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.NodebInfo, connectionStatus entities.ConnectionStatus) common.IRNibError {
+       if nodebInfo.ConnectionStatus == connectionStatus {
+               return nil
+       }
+
        nodebInfo.ConnectionStatus = connectionStatus;
        err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
 
        if err != nil {
-               m.logger.Errorf("#updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err)
+               m.logger.Errorf("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Failed updating RAN's connection status to %s in rNib. Error: %v", nodebInfo.RanName, connectionStatus, err)
                return err
        }
 
-       m.logger.Infof("#updateNodebInfoStatus - RAN name: %s - Successfully updated RAN's connection status to %s in rNib", nodebInfo.RanName, connectionStatus)
+       m.logger.Infof("#RanReconnectionManager.updateNodebInfoStatus - RAN name: %s - Successfully updated RAN's connection status to %s in rNib", nodebInfo.RanName, connectionStatus)
        return nil
 }
 
 func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) common.IRNibError {
        connectionStatus := nodebInfo.GetConnectionStatus()
-       m.logger.Warnf("#setConnectionStatusOfUnconnectableRan - RAN name: %s, RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
+       m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s, RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts)
 
        if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN {
                return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN)
        }
 
        if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts {
-               m.logger.Warnf("#setConnectionStatusOfUnconnectableRan - RAN name: %s - RAN's connection attempts are greater than %d", nodebInfo.RanName, m.config.MaxConnectionAttempts)
+               m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s - RAN's connection attempts are greater than %d", nodebInfo.RanName, m.config.MaxConnectionAttempts)
                return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED)
        }
 
index 68c31ce..f368246 100644 (file)
@@ -56,52 +56,60 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderM
        return logger, readerMock, writerMock, ranReconnectionManager
 }
 
-func TestLostConnectionFetchingNodebFailure(t *testing.T) {
-       _, readerMock, _, ranReconnectionManager := initRanLostConnectionTest(t)
+func TestRanReconnectionGetNodebFailure(t *testing.T) {
+       _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
        ranName := "test"
        var nodebInfo *entities.NodebInfo
        readerMock.On("GetNodeb", ranName).Return(nodebInfo, common.NewInternalError(errors.New("Error")))
        err := ranReconnectionManager.ReconnectRan(ranName)
        assert.NotNil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNotCalled(t, "UpdateNodebInfo")
 }
 
-func TestLostConnectionUpdatingNodebForUnconnectableRanFailure(t *testing.T) {
+func TestShutdownRanReconnection(t *testing.T) {
        _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
        ranName := "test"
-       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}
        var rnibErr common.IRNibError
        readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
-       updatedNodebInfo := *origNodebInfo
-       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
-       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
        err := ranReconnectionManager.ReconnectRan(ranName)
-       assert.NotNil(t, err)
+       assert.Nil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNotCalled(t, "UpdateNodebInfo")
 }
 
-func TestLostConnectionOfConnectedRanWithMaxAttempts(t *testing.T) {
+func TestShuttingdownRanReconnection(t *testing.T) {
        _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
        ranName := "test"
-       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED, ConnectionAttempts: 20}
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
        var rnibErr common.IRNibError
        readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
        updatedNodebInfo := *origNodebInfo
-       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
        writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr)
        err := ranReconnectionManager.ReconnectRan(ranName)
        assert.Nil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
 }
 
-func TestLostConnectionOfShutdownRan(t *testing.T) {
-       _, readerMock, _, ranReconnectionManager := initRanLostConnectionTest(t)
+func TestConnectingRanWithMaxAttemptsReconnection(t *testing.T) {
+       _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
        ranName := "test"
-       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN}
+       origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20}
        var rnibErr common.IRNibError
        readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
+       updatedNodebInfo := *origNodebInfo
+       updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr)
        err := ranReconnectionManager.ReconnectRan(ranName)
        assert.Nil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
 }
 
-func TestLostConnectionOfShuttingdownRan(t *testing.T) {
+func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) {
        _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
        ranName := "test"
        origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN}
@@ -109,9 +117,11 @@ func TestLostConnectionOfShuttingdownRan(t *testing.T) {
        readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr)
        updatedNodebInfo := *origNodebInfo
        updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_SHUT_DOWN
-       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr)
+       writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error")))
        err := ranReconnectionManager.ReconnectRan(ranName)
-       assert.Nil(t, err)
+       assert.NotNil(t, err)
+       readerMock.AssertCalled(t, "GetNodeb", ranName)
+       writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
 }
 
 // TODO: should extract to test_utils
index cb24472..f6fe1d2 100644 (file)
@@ -38,21 +38,20 @@ func NewRanSetupManager(logger *logger.Logger, rmrService *services.RmrService,
        return &RanSetupManager{
                logger:             logger,
                rnibWriterProvider: rnibWriterProvider,
-               rmrService        : rmrService,
+               rmrService:         rmrService,
        }
 }
 
-
 // Update retries and connection status (connecting)
 func (m *RanSetupManager) updateConnectionStatusConnecting(nodebInfo *entities.NodebInfo) error {
        // Update retries and connection status (connecting)
        nodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING
        nodebInfo.ConnectionAttempts++
-       err:= m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
+       err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
        if err != nil {
-               m.logger.Errorf("#ran_setup_manager.updateConnectionStatusConnecting - failed to update RAN's connection status to CONNECTING: %s", err)
+               m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - failed to update RAN's connection status to CONNECTING: %s", err)
        } else {
-               m.logger.Infof("#ran_setup_manager.updateConnectionStatusConnecting - successfully updated RAN's connection status to CONNECTING: %s", err)
+               m.logger.Infof("#RanSetupManager.updateConnectionStatusConnecting - successfully updated RAN's connection status to CONNECTING")
        }
        return err
 }
@@ -64,9 +63,9 @@ func (m *RanSetupManager) updateConnectionStatusDisconnected(nodebInfo *entities
        nodebInfo.ConnectionAttempts--
        err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo)
        if err != nil {
-               m.logger.Errorf("#ran_setup_manager.updateConnectionStatusDisconnected - failed to update RAN's connection status to DISCONNECTED : %s", err)
+               m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - failed to update RAN's connection status to DISCONNECTED : %s", err)
        } else {
-               m.logger.Errorf("#ran_setup_manager.updateConnectionStatusDisconnected - successfully updated RAN's connection status to DISCONNECTED : %s", err)
+               m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - successfully updated RAN's connection status to DISCONNECTED")
        }
        return err
 }
@@ -80,11 +79,11 @@ func (m *RanSetupManager) prepareSetupRequest(nodebInfo *entities.NodebInfo) (in
                return rmrMsgType, request, nil
        case entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST:
                rmrMsgType := rmrCgo.RIC_ENDC_X2_SETUP_REQ
-               request:= models.NewE2RequestMessage(nodebInfo.RanName /*tid*/, nodebInfo.Ip, uint16(nodebInfo.Port), nodebInfo.RanName, e2pdus.PackedEndcX2setupRequest)
+               request := models.NewE2RequestMessage(nodebInfo.RanName /*tid*/, nodebInfo.Ip, uint16(nodebInfo.Port), nodebInfo.RanName, e2pdus.PackedEndcX2setupRequest)
                return rmrMsgType, request, nil
        }
 
-       m.logger.Errorf("#ran_setup_manager.ExecuteSetup - unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol)
+       m.logger.Errorf("#RanSetupManager.ExecuteSetup - unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol)
        return 0, nil, e2managererrors.NewInternalError()
 }
 
@@ -97,15 +96,15 @@ func (m *RanSetupManager) ExecuteSetup(nodebInfo *entities.NodebInfo) error {
        }
 
        // Build the endc/x2 setup request
-       rmrMsgType,request, err := m.prepareSetupRequest(nodebInfo)
+       rmrMsgType, request, err := m.prepareSetupRequest(nodebInfo)
        if err != nil {
                return err
        }
-       
+
        // Send the endc/x2 setup request
        response := &models.NotificationResponse{MgsType: rmrMsgType, RanName: nodebInfo.RanName, Payload: request.GetMessageAsBytes(m.logger)}
        if err := m.rmrService.SendRmrMessage(response); err != nil {
-               m.logger.Errorf("#ran_setup_manager.ExecuteSetup - failed to send setup request to RMR: %s", err)
+               m.logger.Errorf("#RanSetupManager.ExecuteSetup - failed to send setup request to RMR: %s", err)
 
                // Decrement retries and connection status (disconnected)
                if err := m.updateConnectionStatusDisconnected(nodebInfo); err != nil {
@@ -114,5 +113,6 @@ func (m *RanSetupManager) ExecuteSetup(nodebInfo *entities.NodebInfo) error {
 
                return e2managererrors.NewRmrError()
        }
+
        return nil
 }
index 1a0b60b..72f9eb8 100644 (file)
@@ -156,11 +156,7 @@ func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) comm
                return rNibErr
        }
 
-       nodebIdKey, rNibErr := common.ValidateAndBuildNodeBIdKey(nodebInfo.GetNodeType().String(), nodebInfo.GlobalNbId.GetPlmnId(), nodebInfo.GlobalNbId.GetNbId())
-
-       if rNibErr != nil {
-               return rNibErr
-       }
+       nodebIdKey, buildNodebIdKeyError := common.ValidateAndBuildNodeBIdKey(nodebInfo.GetNodeType().String(), nodebInfo.GlobalNbId.GetPlmnId(), nodebInfo.GlobalNbId.GetNbId())
 
        data, err := proto.Marshal(nodebInfo)
 
@@ -169,7 +165,12 @@ func (w *rNibWriterInstance) UpdateNodebInfo(nodebInfo *entities.NodebInfo) comm
        }
 
        var pairs []interface{}
-       pairs = append(pairs, nodebNameKey, data, nodebIdKey, data)
+       pairs = append(pairs, nodebNameKey, data)
+
+       if buildNodebIdKeyError == nil {
+               pairs = append(pairs, nodebIdKey, data)
+       }
+
        err = (*w.sdl).Set(pairs)
 
        if err != nil {
index 14abb1a..63a5d18 100644 (file)
@@ -131,10 +131,8 @@ func TestUpdateNodebInfoMissingInventoryNameFailure(t *testing.T) {
        assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
 }
 
-func TestUpdateNodebInfoMissingGlobalNbIdFailure(t *testing.T) {
+func TestUpdateNodebInfoMissingGlobalNbId(t *testing.T) {
        inventoryName := "name"
-       plmnId := "02f829"
-       nbId := "4a952a0a"
        writerPool = nil
        sdlInstanceMock := initSdlInstanceMock(namespace, 1)
        w := GetRNibWriter()
@@ -148,16 +146,12 @@ func TestUpdateNodebInfoMissingGlobalNbIdFailure(t *testing.T) {
        var setExpected []interface{}
 
        nodebNameKey := fmt.Sprintf("RAN:%s", inventoryName)
-       nodebIdKey := fmt.Sprintf("ENB:%s:%s", plmnId, nbId)
        setExpected = append(setExpected, nodebNameKey, data)
-       setExpected = append(setExpected, nodebIdKey, data)
-
        sdlInstanceMock.On("Set", []interface{}{setExpected}).Return(e)
 
        rNibErr := w.UpdateNodebInfo(nodebInfo)
 
-       assert.NotNil(t, rNibErr)
-       assert.Equal(t, common.VALIDATION_ERROR, rNibErr.GetCode())
+       assert.Nil(t, rNibErr)
 }
 
 func TestSaveEnb(t *testing.T) {