From 6101f93d7348c51217f773c859c348c33a0f6802 Mon Sep 17 00:00:00 2001 From: is005q Date: Thu, 29 Aug 2019 18:15:03 +0300 Subject: [PATCH] [RICPLT-1853] Fix some log messages and adjustments Change-Id: I2786e2ff2c5ae23a2217fb7c6b45c4766c982c46 Signed-off-by: is005q --- E2Manager/handlers/ran_lost_connection_handler.go | 7 +-- E2Manager/managers/ran_reconnection_manager.go | 16 ++++--- .../managers/ran_reconnection_manager_test.go | 52 ++++++++++++++++++---- E2Manager/managers/ran_setup_manager.go | 18 ++++---- 4 files changed, 65 insertions(+), 28 deletions(-) diff --git a/E2Manager/handlers/ran_lost_connection_handler.go b/E2Manager/handlers/ran_lost_connection_handler.go index 980c867..1da2d12 100644 --- a/E2Manager/handlers/ran_lost_connection_handler.go +++ b/E2Manager/handlers/ran_lost_connection_handler.go @@ -44,10 +44,5 @@ func (handler RanLostConnectionHandler) Handle(logger *logger.Logger, e2Sessions 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) - return - } + _ = handler.ranReconnectionManager.ReconnectRan(ranName) } diff --git a/E2Manager/managers/ran_reconnection_manager.go b/E2Manager/managers/ran_reconnection_manager.go index ec521a1..87a656e 100644 --- a/E2Manager/managers/ran_reconnection_manager.go +++ b/E2Manager/managers/ran_reconnection_manager.go @@ -57,11 +57,13 @@ func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error { return rnibErr } + m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - RAN's connection status: %s, RAN's connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionStatus, nodebInfo.ConnectionAttempts) + if !m.canReconnectRan(nodebInfo) { - m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN", inventoryName) return m.setConnectionStatusOfUnconnectableRan(nodebInfo) } + err := m.ranSetupManager.ExecuteSetup(nodebInfo) if err != nil { @@ -69,7 +71,6 @@ func (m *RanReconnectionManager) ReconnectRan(inventoryName string) error { return err } - m.logger.Infof("#RanReconnectionManager.ReconnectRan - RAN name: %s - Successfully done executing setup. RAN's connection attempts: %d", inventoryName, nodebInfo.ConnectionAttempts) return nil } @@ -92,20 +93,25 @@ func (m *RanReconnectionManager) updateNodebInfoStatus(nodebInfo *entities.Nodeb return err } - m.logger.Infof("#RanReconnectionManager.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 rNib. RAN's current connection status: %s", nodebInfo.RanName, nodebInfo.ConnectionStatus) return nil } func (m *RanReconnectionManager) setConnectionStatusOfUnconnectableRan(nodebInfo *entities.NodebInfo) common.IRNibError { connectionStatus := nodebInfo.GetConnectionStatus() - 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_SHUT_DOWN { + m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUT_DOWN", nodebInfo.RanName) + return nil + } if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN { + m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: connection status is SHUTTING_DOWN", nodebInfo.RanName) return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_SHUT_DOWN) } if int(nodebInfo.GetConnectionAttempts()) >= m.config.MaxConnectionAttempts { - m.logger.Warnf("#RanReconnectionManager.setConnectionStatusOfUnconnectableRan - RAN name: %s - RAN's connection attempts are greater than %d", nodebInfo.RanName, m.config.MaxConnectionAttempts) + m.logger.Warnf("#RanReconnectionManager.ReconnectRan - RAN name: %s - Cannot reconnect RAN. Reason: RAN's connection attempts exceeded the limit (%d)", nodebInfo.RanName, m.config.MaxConnectionAttempts) return m.updateNodebInfoStatus(nodebInfo, entities.ConnectionStatus_DISCONNECTED) } diff --git a/E2Manager/managers/ran_reconnection_manager_test.go b/E2Manager/managers/ran_reconnection_manager_test.go index f368246..8eaf385 100644 --- a/E2Manager/managers/ran_reconnection_manager_test.go +++ b/E2Manager/managers/ran_reconnection_manager_test.go @@ -32,16 +32,18 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/reader" "github.com/pkg/errors" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "testing" ) -func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) { +func initRanLostConnectionTest(t *testing.T) (*logger.Logger,*mocks.RmrMessengerMock, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) { logger, err := logger.InitLogger(logger.DebugLevel) if err != nil { t.Errorf("#... - failed to initialize logger, error: %s", err) } - rmrService := getRmrService(&mocks.RmrMessengerMock{}, logger) + rmrMessengerMock := &mocks.RmrMessengerMock{} + rmrService := getRmrService(rmrMessengerMock, logger) readerMock := &mocks.RnibReaderMock{} rnibReaderProvider := func() reader.RNibReader { @@ -53,11 +55,11 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RnibReaderM } ranReconnectionManager := NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibReaderProvider, rnibWriterProvider, rmrService) - return logger, readerMock, writerMock, ranReconnectionManager + return logger,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager } func TestRanReconnectionGetNodebFailure(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" var nodebInfo *entities.NodebInfo readerMock.On("GetNodeb", ranName).Return(nodebInfo, common.NewInternalError(errors.New("Error"))) @@ -68,7 +70,7 @@ func TestRanReconnectionGetNodebFailure(t *testing.T) { } func TestShutdownRanReconnection(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(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} var rnibErr common.IRNibError @@ -80,7 +82,7 @@ func TestShutdownRanReconnection(t *testing.T) { } func TestShuttingdownRanReconnection(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(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} var rnibErr common.IRNibError @@ -95,7 +97,7 @@ func TestShuttingdownRanReconnection(t *testing.T) { } func TestConnectingRanWithMaxAttemptsReconnection(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) + _,_, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) ranName := "test" origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20} var rnibErr common.IRNibError @@ -110,7 +112,7 @@ func TestConnectingRanWithMaxAttemptsReconnection(t *testing.T) { } func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) { - _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(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} var rnibErr common.IRNibError @@ -124,6 +126,40 @@ func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) { writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) } +func TestConnectedRanExecuteSetupSuccess(t *testing.T) { + _,rmrMessengerMock, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t) + ranName := "test" + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol:entities.E2ApplicationProtocol_ENDC_X2_SETUP_REQUEST} + var rnibErr common.IRNibError + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo := *origNodebInfo + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING + updatedNodebInfo.ConnectionAttempts++ + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(nil) + rmrMessengerMock.On("SendMsg",mock.Anything, mock.AnythingOfType("int")).Return(&rmrCgo.MBuf{},nil) + err := ranReconnectionManager.ReconnectRan(ranName) + assert.Nil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) + rmrMessengerMock.AssertNumberOfCalls(t, "SendMsg", 1) +} + +func TestConnectedRanExecuteSetupFailure(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} + var rnibErr common.IRNibError + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo := *origNodebInfo + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_CONNECTING + updatedNodebInfo.ConnectionAttempts++ + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error"))) + err := ranReconnectionManager.ReconnectRan(ranName) + assert.NotNil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) +} + // TODO: should extract to test_utils func getRmrService(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *services.RmrService { rmrMessenger := rmrCgo.RmrMessenger(rmrMessengerMock) diff --git a/E2Manager/managers/ran_setup_manager.go b/E2Manager/managers/ran_setup_manager.go index df7119e..a66d4f1 100644 --- a/E2Manager/managers/ran_setup_manager.go +++ b/E2Manager/managers/ran_setup_manager.go @@ -51,9 +51,9 @@ func (m *RanSetupManager) updateConnectionStatusConnecting(nodebInfo *entities.N nodebInfo.ConnectionAttempts++ err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo) if err != nil { - m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - failed to update RAN's connection status to CONNECTING: %s", err) + m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - Ran name: %s - Failed updating RAN's connection status to CONNECTING : %s", nodebInfo.RanName, err) } else { - m.logger.Infof("#RanSetupManager.updateConnectionStatusConnecting - successfully updated RAN's connection status to CONNECTING") + m.logger.Errorf("#RanSetupManager.updateConnectionStatusConnecting - Ran name: %s - Successfully updated rNib. RAN's current connection status: CONNECTING, RAN's current connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionAttempts) } return err } @@ -65,9 +65,9 @@ func (m *RanSetupManager) updateConnectionStatusDisconnected(nodebInfo *entities nodebInfo.ConnectionAttempts-- err := m.rnibWriterProvider().UpdateNodebInfo(nodebInfo) if err != nil { - m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - failed to update RAN's connection status to DISCONNECTED : %s", err) + m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - Ran name: %s - Failed updating RAN's connection status to DISCONNECTED : %s", nodebInfo.RanName, err) } else { - m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - successfully updated RAN's connection status to DISCONNECTED") + m.logger.Errorf("#RanSetupManager.updateConnectionStatusDisconnected - Ran name: %s - Successfully updated rNib. RAN's current connection status: DISCONNECTED, RAN's current connection attempts: %d", nodebInfo.RanName, nodebInfo.ConnectionAttempts) } return err } @@ -85,7 +85,7 @@ func (m *RanSetupManager) prepareSetupRequest(nodebInfo *entities.NodebInfo) (in return rmrMsgType, request, nil } - m.logger.Errorf("#RanSetupManager.ExecuteSetup - unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol) + m.logger.Errorf("#RanSetupManager.ExecuteSetup - Unsupported nodebInfo.E2ApplicationProtocol %d ", nodebInfo.E2ApplicationProtocol) return 0, nil, e2managererrors.NewInternalError() } @@ -98,23 +98,23 @@ func (m *RanSetupManager) ExecuteSetup(nodebInfo *entities.NodebInfo) error { // Update retries and connection status (connecting) if err := m.updateConnectionStatusConnecting(nodebInfo); err != nil { - delete(m.rmrService.E2sessions,nodebInfo.RanName) + delete(m.rmrService.E2sessions, nodebInfo.RanName) return e2managererrors.NewRnibDbError() } // Build the endc/x2 setup request rmrMsgType, request, err := m.prepareSetupRequest(nodebInfo) if err != nil { - delete(m.rmrService.E2sessions,nodebInfo.RanName) + delete(m.rmrService.E2sessions, nodebInfo.RanName) 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("#RanSetupManager.ExecuteSetup - failed to send setup request to RMR: %s", err) + m.logger.Errorf("#RanSetupManager.ExecuteSetup - failed sending setup request to RMR: %s", err) - delete(m.rmrService.E2sessions,nodebInfo.RanName) + delete(m.rmrService.E2sessions, nodebInfo.RanName) // Decrement retries and connection status (disconnected) if err := m.updateConnectionStatusDisconnected(nodebInfo); err != nil { -- 2.16.6