From: idanshal Date: Sun, 1 Mar 2020 14:45:35 +0000 (+0200) Subject: [RIC-196] some minor fixes after acceptance X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=7c0e66c0cc290ab9803946e43c1c0d68dc62b9c5;p=ric-plt%2Fe2mgr.git [RIC-196] some minor fixes after acceptance Change-Id: I9e985a5d9a16df4b811977787e1a250d8096e996 Signed-off-by: idanshal --- diff --git a/Automation/Tests/Lost_Connection/Lost_Connetion_CONNECTING_TO_DISCONNECTED.robot b/Automation/Tests/Lost_Connection/LostConnectionTestConnectedRan.robot similarity index 79% rename from Automation/Tests/Lost_Connection/Lost_Connetion_CONNECTING_TO_DISCONNECTED.robot rename to Automation/Tests/Lost_Connection/LostConnectionTestConnectedRan.robot index 5fdc853..43c1166 100644 --- a/Automation/Tests/Lost_Connection/Lost_Connetion_CONNECTING_TO_DISCONNECTED.robot +++ b/Automation/Tests/Lost_Connection/LostConnectionTestConnectedRan.robot @@ -31,16 +31,22 @@ Library REST ${url} *** Test Cases *** -Pre Condition for Connecting - no simu - Run And Return Rc And Output ${stop_simu} - ${result}= Run And Return Rc And Output ${docker_command} - Should Be Equal As Integers ${result[1]} ${docker_number-1} +prepare logs for tests + Remove log files + Save logs -Setup Ran - Sleep 1s +Setup Ran and verify it's CONNECTED and associated Post Request setup node b x-2 - Integer response status 204 + Integer response status 204 + Get Request node b enb test1 + Integer response status 200 + String response body ranName test1 + String response body connectionStatus CONNECTED + String response body associatedE2tInstanceAddress e2t.att.com:38000 + +Restart simulator + Restart simulator Verify connection status is DISCONNECTED and RAN is not associated with E2T instance Sleep 5s diff --git a/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go index 99292b3..a1043a7 100644 --- a/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go @@ -60,7 +60,7 @@ func TestLostConnectionHandlerFailure(t *testing.T) { ranDisconnectionManagerMock.AssertCalled(t, "DisconnectRan", ranName) } -func setupLostConnectionHandlerTestWithRealReconnectionManager(t *testing.T, isSuccessfulHttpPost bool) (RanLostConnectionHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) { +func setupLostConnectionHandlerTestWithRealDisconnectionManager(t *testing.T, isSuccessfulHttpPost bool) (RanLostConnectionHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) { logger, _ := logger.InitLogger(logger.InfoLevel) config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3} @@ -74,7 +74,7 @@ func setupLostConnectionHandlerTestWithRealReconnectionManager(t *testing.T, isS ranDisconnectionManager := managers.NewRanDisconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, e2tAssociationManager) handler := NewRanLostConnectionHandler(logger, ranDisconnectionManager) - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20, AssociatedE2TInstanceAddress: e2tAddress} + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo1 := *origNodebInfo @@ -108,8 +108,8 @@ func mockHttpClient(httpClientMock *mocks.HttpClientMock, isSuccessful bool) { httpClientMock.On("Post", clients.DissociateRanE2TInstanceApiSuffix, "application/json", body).Return(&http.Response{StatusCode: respStatusCode, Body: respBody}, nil) } -func TestLostConnectionHandlerFailureWithRealReconnectionManager(t *testing.T) { - handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealReconnectionManager(t, false) +func TestLostConnectionHandlerFailureWithRealDisconnectionManager(t *testing.T) { + handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealDisconnectionManager(t, false) notificationRequest := models.NotificationRequest{RanName: ranName} handler.Handle(¬ificationRequest) @@ -120,8 +120,8 @@ func TestLostConnectionHandlerFailureWithRealReconnectionManager(t *testing.T) { writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) } -func TestLostConnectionHandlerSuccessWithRealReconnectionManager(t *testing.T) { - handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealReconnectionManager(t, true) +func TestLostConnectionHandlerSuccessWithRealDisconnectionManager(t *testing.T) { + handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealDisconnectionManager(t, true) notificationRequest := models.NotificationRequest{RanName: ranName} handler.Handle(¬ificationRequest) diff --git a/E2Manager/managers/ran_disconnection_manager.go b/E2Manager/managers/ran_disconnection_manager.go index 3c4479a..b70648a 100644 --- a/E2Manager/managers/ran_disconnection_manager.go +++ b/E2Manager/managers/ran_disconnection_manager.go @@ -64,6 +64,8 @@ func (m *RanDisconnectionManager) DisconnectRan(inventoryName string) error { return nil } + nodebInfo.ConnectionAttempts = 0; + if connectionStatus == entities.ConnectionStatus_SHUTTING_DOWN { return m.updateNodebInfo(nodebInfo, entities.ConnectionStatus_SHUT_DOWN) } diff --git a/E2Manager/managers/ran_disconnection_manager_test.go b/E2Manager/managers/ran_disconnection_manager_test.go index 644c552..6ef0f54 100644 --- a/E2Manager/managers/ran_disconnection_manager_test.go +++ b/E2Manager/managers/ran_disconnection_manager_test.go @@ -57,7 +57,7 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RmrMessenge return logger, rmrMessengerMock, readerMock, writerMock, ranDisconnectionManager, httpClient } -func TestRanReconnectionGetNodebFailure(t *testing.T) { +func TestRanDisconnectionGetNodebFailure(t *testing.T) { _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) var nodebInfo *entities.NodebInfo @@ -68,7 +68,7 @@ func TestRanReconnectionGetNodebFailure(t *testing.T) { writerMock.AssertNotCalled(t, "UpdateNodebInfo") } -func TestShutdownRanReconnection(t *testing.T) { +func TestShutdownRan(t *testing.T) { _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUT_DOWN} @@ -80,7 +80,7 @@ func TestShutdownRanReconnection(t *testing.T) { writerMock.AssertNotCalled(t, "UpdateNodebInfo") } -func TestShuttingdownRanReconnection(t *testing.T) { +func TestShuttingdownRan(t *testing.T) { _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} @@ -95,7 +95,37 @@ func TestShuttingdownRanReconnection(t *testing.T) { writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) } -func TestConnectingRanDissociateSucceeds(t *testing.T) { +func TestShuttingDownRanUpdateNodebInfoFailure(t *testing.T) { + _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) + + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} + var rnibErr error + 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 := ranDisconnectionManager.DisconnectRan(ranName) + assert.NotNil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) +} + +func TestConnectingRanUpdateNodebInfoFailure(t *testing.T) { + _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) + + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING} + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo := *origNodebInfo + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error"))) + err := ranDisconnectionManager.DisconnectRan(ranName) + assert.NotNil(t, err) + readerMock.AssertCalled(t, "GetNodeb", ranName) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) +} + +func TestConnectingRanDisconnectSucceeds(t *testing.T) { _, _, readerMock, writerMock, ranDisconnectionManager, httpClient := initRanLostConnectionTest(t) origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: E2TAddress} @@ -120,10 +150,10 @@ func TestConnectingRanDissociateSucceeds(t *testing.T) { writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) } -func TestConnectingRanDissociateFails(t *testing.T) { - _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) +func TestConnectingRanDissociateFailsRmError(t *testing.T) { + _, _, readerMock, writerMock, ranDisconnectionManager, httpClient := initRanLostConnectionTest(t) - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress} + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: E2TAddress} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) updatedNodebInfo1 := *origNodebInfo @@ -133,43 +163,38 @@ func TestConnectingRanDissociateFails(t *testing.T) { updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED updatedNodebInfo2.AssociatedE2TInstanceAddress = "" writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(rnibErr) - e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}} - readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, common.NewInternalError(errors.New("Error"))) + e2tInstance := &entities.E2TInstance{Address: E2TAddress, AssociatedRanList: []string{ranName}} + readerMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil) + e2tInstanceToSave := * e2tInstance + e2tInstanceToSave.AssociatedRanList = []string{} + writerMock.On("SaveE2TInstance", &e2tInstanceToSave).Return(nil) + mockHttpClient(httpClient, clients.DissociateRanE2TInstanceApiSuffix, false) err := ranDisconnectionManager.DisconnectRan(ranName) - assert.NotNil(t, err) + assert.Nil(t, err) readerMock.AssertCalled(t, "GetNodeb", ranName) writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) - writerMock.AssertNotCalled(t, "SaveE2TInstance", ) } -func TestShuttingDownRanUpdateNodebInfoFailure(t *testing.T) { +func TestConnectingRanDissociateFailsDbError(t *testing.T) { _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_SHUTTING_DOWN} - var rnibErr error - 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 := ranDisconnectionManager.DisconnectRan(ranName) - assert.NotNil(t, err) - readerMock.AssertCalled(t, "GetNodeb", ranName) - writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) -} - -func TestRanDisconnectedUpdateNodebInfoFailure(t *testing.T) { - _, _, readerMock, writerMock, ranDisconnectionManager, _ := initRanLostConnectionTest(t) - - origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING} + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, AssociatedE2TInstanceAddress: e2tAddress} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) - updatedNodebInfo := *origNodebInfo - updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED - writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(common.NewInternalError(errors.New("Error"))) + updatedNodebInfo1 := *origNodebInfo + updatedNodebInfo1.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + writerMock.On("UpdateNodebInfo", &updatedNodebInfo1).Return(rnibErr) + updatedNodebInfo2 := *origNodebInfo + updatedNodebInfo2.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + updatedNodebInfo2.AssociatedE2TInstanceAddress = "" + writerMock.On("UpdateNodebInfo", &updatedNodebInfo2).Return(rnibErr) + e2tInstance := &entities.E2TInstance{Address: e2tAddress, AssociatedRanList: []string{ranName}} + readerMock.On("GetE2TInstance", e2tAddress).Return(e2tInstance, common.NewInternalError(errors.New("Error"))) err := ranDisconnectionManager.DisconnectRan(ranName) assert.NotNil(t, err) readerMock.AssertCalled(t, "GetNodeb", ranName) - writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) + writerMock.AssertNotCalled(t, "SaveE2TInstance", ) } func initRmrSender(rmrMessengerMock *mocks.RmrMessengerMock, log *logger.Logger) *rmrsender.RmrSender {