+++ /dev/null
-////
-//// 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), ¬ificationRequest, 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), ¬ificationRequest, 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, ¬ificationRequest, 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, ¬ificationRequest, 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, ¬ificationRequest, 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, ¬ificationRequest, 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, ¬ificationRequest, messageChannel)
-//}
}
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)
--- /dev/null
+////
+//// 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), ¬ificationRequest, 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), ¬ificationRequest, nil)
+ ranReconnectionManagerMock.AssertCalled(t, "ReconnectRan", ranName)
+}
\ No newline at end of file
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
}
}
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)
}
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}
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
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
}
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
}
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()
}
}
// 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 {
return e2managererrors.NewRmrError()
}
+
return nil
}
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)
}
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 {
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()
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) {