From 63b5d926f439ca666378697ec81d893fc633dae5 Mon Sep 17 00:00:00 2001 From: Amichai Date: Thu, 26 Dec 2019 15:22:55 +0200 Subject: [PATCH] [RICPLT-2527] Add Automation and UTs Change-Id: I03d2047b3ddefbbd3fef518135076acba117443c Signed-off-by: Amichai --- Automation/Tests/Resource/Keywords.robot | 5 +- Automation/Tests/Resource/resource.robot | 3 +- .../Unhappy/Setup_Request_HttpResponse503.robot | 39 ++++++++++ .../httpmsghandlers/setup_request_handler_test.go | 22 ++++++ .../ran_lost_connection_handler_test.go | 88 +++++++++++++++++++++- .../managers/ran_reconnection_manager_test.go | 20 ++--- 6 files changed, 164 insertions(+), 13 deletions(-) create mode 100644 Automation/Tests/Unhappy/Setup_Request_HttpResponse503.robot diff --git a/Automation/Tests/Resource/Keywords.robot b/Automation/Tests/Resource/Keywords.robot index e2e622f..0f24653 100644 --- a/Automation/Tests/Resource/Keywords.robot +++ b/Automation/Tests/Resource/Keywords.robot @@ -83,7 +83,6 @@ Stop Simulator Run And Return Rc And Output ${stop_simu} - Prepare Simulator For Load Information Run And Return Rc And Output ${stop_simu} Run And Return Rc And Output ${docker_Remove} @@ -166,7 +165,11 @@ Restart simulator ${result}= Run And Return Rc And Output ${docker_command} Should Be Equal As Integers ${result[1]} ${docker_number} +Start RoutingManager Simulator + Run And Return Rc And Output ${start_routingmanager_sim} +Stop RoutingManager Simulator + Run And Return Rc And Output ${stop_routingmanager_sim} diff --git a/Automation/Tests/Resource/resource.robot b/Automation/Tests/Resource/resource.robot index 90c79b2..c37ebaa 100644 --- a/Automation/Tests/Resource/resource.robot +++ b/Automation/Tests/Resource/resource.robot @@ -64,7 +64,8 @@ ${stop_docker_e2} docker stop e2 ${restart_docker_sim} docker restart gnbe2_simu ${Run_Config} docker exec gnbe2_simu pkill gnbe2_simu -INT ${403_reset_message} "Activity X2_RESET rejected. RAN current state DISCONNECTED does not allow its execution " - +${stop_routingmanager_sim} docker stop rm_sim +${start_routingmanager_sim} docker start rm_sim diff --git a/Automation/Tests/Unhappy/Setup_Request_HttpResponse503.robot b/Automation/Tests/Unhappy/Setup_Request_HttpResponse503.robot new file mode 100644 index 0000000..9fe7071 --- /dev/null +++ b/Automation/Tests/Unhappy/Setup_Request_HttpResponse503.robot @@ -0,0 +1,39 @@ +############################################################################## +# +# Copyright (c) 2019 AT&T Intellectual Property. +# +# 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. +# +############################################################################## +# +# This source code is part of the near-RT RIC (RAN Intelligent Controller) +# platform project (RICP). +# + +*** Settings *** +Suite Setup Prepare Enviorment +Resource ../Resource/Keywords.robot +Resource ../Resource/resource.robot +Library REST ${url} +Suite Teardown Start RoutingManager Simulator + +*** Test Cases *** +ENDC-setup - 500 http - 500 RNIB error + Stop RoutingManager Simulator + Set Headers ${header} + POST /v1/nodeb/x2-setup ${json} + Integer response status 503 + Integer response body errorCode 511 + String response body errorMessage No Routing Manager Available + + diff --git a/E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go b/E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go index 7586791..e8a6736 100644 --- a/E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go +++ b/E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go @@ -416,3 +416,25 @@ func TestSetupExistingRanWithAssocE2TInstanceConnectedSuccess(t *testing.T) { e2tInstancesManagerMock.AssertNotCalled(t, "SelectE2TInstance") e2tInstancesManagerMock.AssertNotCalled(t, "AddRanToInstance") } + +func TestSetupExistingRanWithoutAssocE2TInstanceExecuteRoutingManagerError(t *testing.T) { + readerMock, writerMock, handler, _, httpClientMock := initSetupRequestTestBasicMocks(t, entities.E2ApplicationProtocol_X2_SETUP_REQUEST) + nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: "", ConnectionStatus: entities.ConnectionStatus_CONNECTED, E2ApplicationProtocol:entities.E2ApplicationProtocol_X2_SETUP_REQUEST} + readerMock.On("GetNodeb", RanName).Return(nb, nil) + addresses := []string{E2TAddress} + readerMock.On("GetE2TAddresses").Return(addresses, nil) + e2tInstance := &entities.E2TInstance{Address: E2TAddress, State: entities.Active} + readerMock.On("GetE2TInstances", addresses).Return([]*entities.E2TInstance{e2tInstance}, nil) + + data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress, RanName)} + marshaled, _ := json.Marshal(data) + body := bytes.NewBuffer(marshaled) + respBody := ioutil.NopCloser(bytes.NewBufferString("")) + httpClientMock.On("Post", clients.AssociateRanToE2TInstanceApiSuffix, "application/json", body).Return(&http.Response{StatusCode: http.StatusBadRequest, Body: respBody}, nil) + + _, err := handler.Handle(models.SetupRequest{"127.0.0.1", 8080, RanName,}) + assert.IsType(t, &e2managererrors.RoutingManagerError{}, err) + writerMock.AssertExpectations(t) + readerMock.AssertExpectations(t) + httpClientMock.AssertExpectations(t) +} diff --git a/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go index 60755ab..1220c79 100644 --- a/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go +++ b/E2Manager/handlers/rmrmsghandlers/ran_lost_connection_handler_test.go @@ -19,16 +19,28 @@ package rmrmsghandlers import ( + "bytes" + "e2mgr/clients" + "e2mgr/configuration" "e2mgr/logger" + "e2mgr/managers" "e2mgr/mocks" "e2mgr/models" + "e2mgr/services" + "encoding/json" + "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities" "github.com/pkg/errors" + "io/ioutil" + "net/http" "testing" ) +const ranName = "test" +const e2tAddress = "10.10.2.15:9800" + 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) @@ -39,7 +51,7 @@ func TestLostConnectionHandlerSuccess(t *testing.T) { 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")) @@ -47,3 +59,75 @@ func TestLostConnectionHandlerFailure(t *testing.T) { handler.Handle(¬ificationRequest) ranReconnectionManagerMock.AssertCalled(t, "ReconnectRan", ranName) } + +func setupLostConnectionHandlerTestWithRealReconnectionManager(t *testing.T, isSuccessfulHttpPost bool) (RanLostConnectionHandler, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) { + logger, _ := logger.InitLogger(logger.InfoLevel) + config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3} + + rmrMessengerMock := &mocks.RmrMessengerMock{} + rmrSender := initRmrSender(rmrMessengerMock, logger) + readerMock := &mocks.RnibReaderMock{} + writerMock := &mocks.RnibWriterMock{} + rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock) + e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger) + ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService) + httpClientMock := &mocks.HttpClientMock{} + routingManagerClient := clients.NewRoutingManagerClient(logger, config, httpClientMock) + e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient) + ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tAssociationManager) + handler := NewRanLostConnectionHandler(logger, ranReconnectionManager) + + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20, AssociatedE2TInstanceAddress: e2tAddress} + var rnibErr error + readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) + updatedNodebInfo := *origNodebInfo + updatedNodebInfo.ConnectionStatus = entities.ConnectionStatus_DISCONNECTED + updatedNodebInfo.AssociatedE2TInstanceAddress = "" + writerMock.On("UpdateNodebInfo", &updatedNodebInfo).Return(rnibErr) + 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(httpClientMock, isSuccessfulHttpPost) + + return handler, readerMock, writerMock, httpClientMock +} + +func mockHttpClient(httpClientMock *mocks.HttpClientMock, isSuccessful bool) { + data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(e2tAddress, RanName)} + marshaled, _ := json.Marshal(data) + body := bytes.NewBuffer(marshaled) + respBody := ioutil.NopCloser(bytes.NewBufferString("")) + var respStatusCode int + if isSuccessful { + respStatusCode = http.StatusCreated + } else { + respStatusCode = http.StatusBadRequest + } + 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) + + notificationRequest := models.NotificationRequest{RanName: ranName} + handler.Handle(¬ificationRequest) + + readerMock.AssertExpectations(t) + writerMock.AssertExpectations(t) + httpClientMock.AssertExpectations(t) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) +} + +func TestLostConnectionHandlerSuccessWithRealReconnectionManager(t *testing.T) { + handler, readerMock, writerMock, httpClientMock := setupLostConnectionHandlerTestWithRealReconnectionManager(t, true) + + notificationRequest := models.NotificationRequest{RanName: ranName} + handler.Handle(¬ificationRequest) + + readerMock.AssertExpectations(t) + writerMock.AssertExpectations(t) + httpClientMock.AssertExpectations(t) + writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2) +} diff --git a/E2Manager/managers/ran_reconnection_manager_test.go b/E2Manager/managers/ran_reconnection_manager_test.go index e5e7ef3..c4c30d6 100644 --- a/E2Manager/managers/ran_reconnection_manager_test.go +++ b/E2Manager/managers/ran_reconnection_manager_test.go @@ -37,6 +37,9 @@ import ( "testing" ) +const ranName = "test" +const e2tAddress = "10.10.2.15:9800" + func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RmrMessengerMock, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager, *mocks.HttpClientMock) { logger, err := logger.InitLogger(logger.DebugLevel) if err != nil { @@ -63,7 +66,7 @@ func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RmrMessenge 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) @@ -74,7 +77,7 @@ func TestRanReconnectionGetNodebFailure(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_SHUT_DOWN} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) @@ -86,7 +89,7 @@ func TestShutdownRanReconnection(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_SHUTTING_DOWN} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) @@ -101,7 +104,7 @@ func TestShuttingdownRanReconnection(t *testing.T) { func TestConnectingRanWithMaxAttemptsReconnectionDissociateSucceeds(t *testing.T) { _, _, readerMock, writerMock, ranReconnectionManager, httpClient:= initRanLostConnectionTest(t) - ranName := "test" + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20, AssociatedE2TInstanceAddress: E2TAddress} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) @@ -123,8 +126,7 @@ func TestConnectingRanWithMaxAttemptsReconnectionDissociateSucceeds(t *testing.T func TestConnectingRanWithMaxAttemptsReconnectionDissociateFails(t *testing.T) { _, _, readerMock, writerMock, ranReconnectionManager, _ := initRanLostConnectionTest(t) - ranName := "test" - e2tAddress := "10.0.2.15" + origNodebInfo := &entities.NodebInfo{RanName: ranName, GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTING, ConnectionAttempts: 20, AssociatedE2TInstanceAddress: e2tAddress} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) @@ -143,7 +145,7 @@ func TestConnectingRanWithMaxAttemptsReconnectionDissociateFails(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} var rnibErr error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) @@ -158,7 +160,7 @@ func TestUnconnectableRanUpdateNodebInfoFailure(t *testing.T) { 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 error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) @@ -176,7 +178,7 @@ func TestConnectedRanExecuteSetupSuccess(t *testing.T) { 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 error readerMock.On("GetNodeb", ranName).Return(origNodebInfo, rnibErr) -- 2.16.6