[RICPLT-2527] Implementation of DissociateRan + UTs
Change-Id: I5a285f4eeed731a051285e0856335105dca9d7f6
Signed-off-by: Amichai <amichai.sichel@intl.att.com>
diff --git a/E2Manager/app/main.go b/E2Manager/app/main.go
index e311dc8..0678611 100644
--- a/E2Manager/app/main.go
+++ b/E2Manager/app/main.go
@@ -65,7 +65,7 @@
routingManagerClient := clients.NewRoutingManagerClient(logger, config, &http.Client{})
e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient)
rmrNotificationHandlerProvider := rmrmsghandlerprovider.NewNotificationHandlerProvider()
- rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient)
+ rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager)
notificationManager := notificationmanager.NewNotificationManager(logger, rmrNotificationHandlerProvider)
rmrReceiver := rmrreceiver.NewRmrReceiver(logger, rmrMessenger, notificationManager)
diff --git a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go
index 18c89ca..c930b0e 100644
--- a/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go
+++ b/E2Manager/handlers/rmrmsghandlers/e2_term_init_notification_handler_test.go
@@ -64,8 +64,9 @@
ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService)
e2tInstancesManagerMock := &mocks.E2TInstancesManagerMock{}
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManagerMock, routingManagerClientMock)
- ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManagerMock)
+ ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tAssociationManager)
handler := NewE2TermInitNotificationHandler(logger, ranReconnectionManager, e2tInstancesManagerMock, routingManagerClientMock)
return logger, handler, readerMock, writerMock, rmrMessengerMock, e2tInstancesManagerMock, routingManagerClientMock
@@ -89,7 +90,8 @@
ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService)
e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger)
- ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManager)
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient)
+ ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tAssociationManager)
handler := NewE2TermInitNotificationHandler(logger, ranReconnectionManager, e2tInstancesManager, routingManagerClient)
return logger, config, handler, readerMock, writerMock, rmrMessengerMock, httpClientMock
}
diff --git a/E2Manager/managers/e2t_association_manager.go b/E2Manager/managers/e2t_association_manager.go
index 3311e60..78ae6d7 100644
--- a/E2Manager/managers/e2t_association_manager.go
+++ b/E2Manager/managers/e2t_association_manager.go
@@ -73,3 +73,34 @@
m.logger.Infof("#E2TAssociationManager.AssociateRan - successfully associated RAN %s with E2T %s", ranName, e2tAddress)
return nil
}
+
+func (m *E2TAssociationManager) DissociateRan(e2tAddress string, ranName string) error {
+ m.logger.Infof("#E2TAssociationManager.DissociateRan - Dissociating RAN %s from E2T Instance address: %s", ranName, e2tAddress)
+
+ nodebInfo, rnibErr := m.rnibDataService.GetNodeb(ranName)
+ if rnibErr != nil {
+ m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed fetching RAN from rNib. Error: %s", ranName, rnibErr)
+ return rnibErr
+ }
+
+ nodebInfo.AssociatedE2TInstanceAddress = ""
+ rnibErr = m.rnibDataService.UpdateNodebInfo(nodebInfo)
+ if rnibErr != nil {
+ m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to update RAN.AssociatedE2TInstanceAddress in rNib. Error: %s", ranName, rnibErr)
+ return rnibErr
+ }
+
+ err := m.e2tInstanceManager.RemoveRanFromInstance(ranName, e2tAddress)
+ if err != nil {
+ m.logger.Errorf("#E2TAssociationManager.DissociateRan - RAN name: %s - Failed to remove RAN from E2T instance %s. Error: %s", ranName, e2tAddress, err)
+ return err
+ }
+
+ err = m.rmClient.DissociateRanE2TInstance(e2tAddress, ranName)
+ if err != nil {
+ m.logger.Errorf("#E2TAssociationManager.DissociateRan - RoutingManager failure: Failed to dissociate RAN %s from E2T %s. Error: %s", ranName, e2tAddress, err)
+ } else {
+ m.logger.Infof("#E2TAssociationManager.DissociateRan - successfully dissociated RAN %s from E2T %s", ranName, e2tAddress)
+ }
+ return nil
+}
diff --git a/E2Manager/managers/e2t_association_manager_test.go b/E2Manager/managers/e2t_association_manager_test.go
index 6754a3b..cdaed68 100644
--- a/E2Manager/managers/e2t_association_manager_test.go
+++ b/E2Manager/managers/e2t_association_manager_test.go
@@ -37,12 +37,10 @@
)
const RanName = "test"
-const BaseRMUrl = "http://10.10.2.15:12020/routingmanager"
func initE2TAssociationManagerTest(t *testing.T) (*E2TAssociationManager, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *mocks.HttpClientMock) {
log := initLog(t)
config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
- config.RoutingManager.BaseUrl = BaseRMUrl
readerMock := &mocks.RnibReaderMock{}
writerMock := &mocks.RnibWriterMock{}
@@ -56,11 +54,10 @@
return manager, readerMock, writerMock, httpClientMock
}
-func mockHttpClientAssociateRan(httpClientMock *mocks.HttpClientMock, isSuccessful bool) {
+func mockHttpClient(httpClientMock *mocks.HttpClientMock, apiSuffix string, isSuccessful bool) {
data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress, RanName)}
marshaled, _ := json.Marshal(data)
body := bytes.NewBuffer(marshaled)
- url := BaseRMUrl + clients.AssociateRanToE2TInstanceApiSuffix
respBody := ioutil.NopCloser(bytes.NewBufferString(""))
var respStatusCode int
if isSuccessful {
@@ -68,12 +65,12 @@
} else {
respStatusCode = http.StatusBadRequest
}
- httpClientMock.On("Post", url, "application/json", body).Return(&http.Response{StatusCode: respStatusCode, Body: respBody}, nil)
+ httpClientMock.On("Post", apiSuffix, "application/json", body).Return(&http.Response{StatusCode: respStatusCode, Body: respBody}, nil)
}
func TestAssociateRanSuccess(t *testing.T) {
manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
- mockHttpClientAssociateRan(httpClientMock, true)
+ mockHttpClient(httpClientMock, clients.AssociateRanToE2TInstanceApiSuffix, true)
nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: "", ConnectionAttempts: 1}
readerMock.On("GetNodeb", RanName).Return(nb, nil)
updatedNb := *nb
@@ -96,7 +93,7 @@
func TestAssociateRanRoutingManagerError(t *testing.T) {
manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
- mockHttpClientAssociateRan(httpClientMock, false)
+ mockHttpClient(httpClientMock, clients.AssociateRanToE2TInstanceApiSuffix, false)
err := manager.AssociateRan(E2TAddress, RanName)
@@ -109,7 +106,7 @@
func TestAssociateRanGetNodebError(t *testing.T) {
manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
- mockHttpClientAssociateRan(httpClientMock, true)
+ mockHttpClient(httpClientMock, clients.AssociateRanToE2TInstanceApiSuffix, true)
var nb *entities.NodebInfo
readerMock.On("GetNodeb", RanName).Return(nb, e2managererrors.NewRnibDbError())
@@ -124,7 +121,7 @@
func TestAssociateRanUpdateNodebError(t *testing.T) {
manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
- mockHttpClientAssociateRan(httpClientMock, true)
+ mockHttpClient(httpClientMock, clients.AssociateRanToE2TInstanceApiSuffix, true)
nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: "", ConnectionAttempts: 1}
readerMock.On("GetNodeb", RanName).Return(nb, nil)
updatedNb := *nb
@@ -143,7 +140,7 @@
func TestAssociateRanGetE2tInstanceError(t *testing.T) {
manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
- mockHttpClientAssociateRan(httpClientMock, true)
+ mockHttpClient(httpClientMock, clients.AssociateRanToE2TInstanceApiSuffix, true)
nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: "", ConnectionAttempts: 1}
readerMock.On("GetNodeb", RanName).Return(nb, nil)
updatedNb := *nb
@@ -164,7 +161,7 @@
func TestAssociateRanSaveE2tInstanceError(t *testing.T) {
manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
- mockHttpClientAssociateRan(httpClientMock, true)
+ mockHttpClient(httpClientMock, clients.AssociateRanToE2TInstanceApiSuffix, true)
nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: "", ConnectionAttempts: 1}
readerMock.On("GetNodeb", RanName).Return(nb, nil)
updatedNb := *nb
@@ -185,3 +182,122 @@
writerMock.AssertExpectations(t)
httpClientMock.AssertExpectations(t)
}
+
+func TestDissociateRanSuccess(t *testing.T) {
+ manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
+ mockHttpClient(httpClientMock, clients.DissociateRanE2TInstanceApiSuffix, true)
+ nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: E2TAddress, ConnectionAttempts: 1}
+ readerMock.On("GetNodeb", RanName).Return(nb, nil)
+ updatedNb := *nb
+ updatedNb.AssociatedE2TInstanceAddress = ""
+ writerMock.On("UpdateNodebInfo", &updatedNb).Return(nil)
+ e2tInstance := &entities.E2TInstance{Address: E2TAddress}
+ e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, RanName)
+ readerMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil)
+ updatedE2tInstance := *e2tInstance
+ updatedE2tInstance.AssociatedRanList = []string{}
+ writerMock.On("SaveE2TInstance", &updatedE2tInstance).Return(nil)
+
+ err := manager.DissociateRan(E2TAddress, RanName)
+
+ assert.Nil(t, err)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ httpClientMock.AssertExpectations(t)
+}
+
+func TestDissociateRanGetNodebError(t *testing.T) {
+ manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
+ var nb *entities.NodebInfo
+ readerMock.On("GetNodeb", RanName).Return(nb, e2managererrors.NewRnibDbError())
+
+ err := manager.DissociateRan(E2TAddress, RanName)
+
+ assert.NotNil(t, err)
+ assert.IsType(t, &e2managererrors.RnibDbError{}, err)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ httpClientMock.AssertExpectations(t)
+}
+
+func TestDissociateRanUpdateNodebError(t *testing.T) {
+ manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
+ nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: E2TAddress, ConnectionAttempts: 1}
+ readerMock.On("GetNodeb", RanName).Return(nb, nil)
+ updatedNb := *nb
+ updatedNb.AssociatedE2TInstanceAddress = ""
+ writerMock.On("UpdateNodebInfo", &updatedNb).Return(e2managererrors.NewRnibDbError())
+
+ err := manager.DissociateRan(E2TAddress, RanName)
+
+ assert.NotNil(t, err)
+ assert.IsType(t, &e2managererrors.RnibDbError{}, err)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ httpClientMock.AssertExpectations(t)
+}
+
+func TestDissociateRanGetE2tInstanceError(t *testing.T) {
+ manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
+ nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: E2TAddress, ConnectionAttempts: 1}
+ readerMock.On("GetNodeb", RanName).Return(nb, nil)
+ updatedNb := *nb
+ updatedNb.AssociatedE2TInstanceAddress = ""
+ writerMock.On("UpdateNodebInfo", &updatedNb).Return(nil)
+ var e2tInstance *entities.E2TInstance
+ readerMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, errors.New("test"))
+
+ err := manager.DissociateRan(E2TAddress, RanName)
+
+ assert.NotNil(t, err)
+ assert.IsType(t, &e2managererrors.RnibDbError{}, err)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ httpClientMock.AssertExpectations(t)
+}
+
+func TestDissociateRanSaveE2tInstanceError(t *testing.T) {
+ manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
+ nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: E2TAddress, ConnectionAttempts: 1}
+ readerMock.On("GetNodeb", RanName).Return(nb, nil)
+ updatedNb := *nb
+ updatedNb.AssociatedE2TInstanceAddress = ""
+ writerMock.On("UpdateNodebInfo", &updatedNb).Return(nil)
+ e2tInstance := &entities.E2TInstance{Address: E2TAddress}
+ e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, RanName)
+ readerMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil)
+ updatedE2tInstance := *e2tInstance
+ updatedE2tInstance.AssociatedRanList = []string{}
+ writerMock.On("SaveE2TInstance", &updatedE2tInstance).Return(errors.New("test"))
+
+ err := manager.DissociateRan(E2TAddress, RanName)
+
+ assert.NotNil(t, err)
+ assert.IsType(t, &e2managererrors.RnibDbError{}, err)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ httpClientMock.AssertExpectations(t)
+}
+
+func TestDissociateRanRoutingManagerError(t *testing.T) {
+ manager, readerMock, writerMock, httpClientMock := initE2TAssociationManagerTest(t)
+ mockHttpClient(httpClientMock, clients.DissociateRanE2TInstanceApiSuffix, false)
+ nb := &entities.NodebInfo{RanName: RanName, AssociatedE2TInstanceAddress: E2TAddress, ConnectionAttempts: 1}
+ readerMock.On("GetNodeb", RanName).Return(nb, nil)
+ updatedNb := *nb
+ updatedNb.AssociatedE2TInstanceAddress = ""
+ writerMock.On("UpdateNodebInfo", &updatedNb).Return(nil)
+ e2tInstance := &entities.E2TInstance{Address: E2TAddress}
+ e2tInstance.AssociatedRanList = append(e2tInstance.AssociatedRanList, RanName)
+ readerMock.On("GetE2TInstance", E2TAddress).Return(e2tInstance, nil)
+ updatedE2tInstance := *e2tInstance
+ updatedE2tInstance.AssociatedRanList = []string{}
+ writerMock.On("SaveE2TInstance", &updatedE2tInstance).Return(nil)
+
+ err := manager.DissociateRan(E2TAddress, RanName)
+
+ assert.Nil(t, err)
+ readerMock.AssertExpectations(t)
+ writerMock.AssertExpectations(t)
+ httpClientMock.AssertExpectations(t)
+}
\ No newline at end of file
diff --git a/E2Manager/managers/e2t_instances_manager.go b/E2Manager/managers/e2t_instances_manager.go
index 4f4017d..0a95f5f 100644
--- a/E2Manager/managers/e2t_instances_manager.go
+++ b/E2Manager/managers/e2t_instances_manager.go
@@ -235,7 +235,7 @@
if err != nil {
m.logger.Errorf("#E2TInstancesManager.RemoveRanFromInstance - E2T Instance address: %s - Failed retrieving E2TInstance. error: %s", e2tAddress, err)
- return err
+ return e2managererrors.NewRnibDbError()
}
i := 0 // output index
@@ -253,7 +253,7 @@
if err != nil {
m.logger.Errorf("#E2TInstancesManager.RemoveRanFromInstance - E2T Instance address: %s - Failed saving E2TInstance. error: %s", e2tAddress, err)
- return err
+ return e2managererrors.NewRnibDbError()
}
m.logger.Infof("#E2TInstancesManager.RemoveRanFromInstance - successfully dissociated RAN %s from E2T %s", ranName, e2tInstance.Address)
diff --git a/E2Manager/managers/notificationmanager/notification_manager_test.go b/E2Manager/managers/notificationmanager/notification_manager_test.go
index bd6798e..ded3f27 100644
--- a/E2Manager/managers/notificationmanager/notification_manager_test.go
+++ b/E2Manager/managers/notificationmanager/notification_manager_test.go
@@ -49,8 +49,9 @@
ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService)
e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger)
routingManagerClient := clients.NewRoutingManagerClient(logger, config, httpClient)
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient)
rmrNotificationHandlerProvider := rmrmsghandlerprovider.NewNotificationHandlerProvider()
- rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager,routingManagerClient)
+ rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager,routingManagerClient, e2tAssociationManager)
notificationManager := NewNotificationManager(logger, rmrNotificationHandlerProvider )
return logger, readerMock, notificationManager
}
diff --git a/E2Manager/managers/ran_reconnection_manager.go b/E2Manager/managers/ran_reconnection_manager.go
index 7a1dab7..530131f 100644
--- a/E2Manager/managers/ran_reconnection_manager.go
+++ b/E2Manager/managers/ran_reconnection_manager.go
@@ -32,20 +32,20 @@
}
type RanReconnectionManager struct {
- logger *logger.Logger
- config *configuration.Configuration
- rnibDataService services.RNibDataService
- ranSetupManager *RanSetupManager
- e2tInstancesManager IE2TInstancesManager
+ logger *logger.Logger
+ config *configuration.Configuration
+ rnibDataService services.RNibDataService
+ ranSetupManager *RanSetupManager
+ e2tAssociationManager *E2TAssociationManager
}
-func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, ranSetupManager *RanSetupManager, e2tInstancesManager IE2TInstancesManager) *RanReconnectionManager {
+func NewRanReconnectionManager(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, ranSetupManager *RanSetupManager, e2tAssociationManager *E2TAssociationManager) *RanReconnectionManager {
return &RanReconnectionManager{
- logger: logger,
- config: config,
- rnibDataService: rnibDataService,
- ranSetupManager: ranSetupManager,
- e2tInstancesManager: e2tInstancesManager,
+ logger: logger,
+ config: config,
+ rnibDataService: rnibDataService,
+ ranSetupManager: ranSetupManager,
+ e2tAssociationManager: e2tAssociationManager,
}
}
@@ -72,7 +72,7 @@
}
if m.isRanExceededConnectionAttempts(nodebInfo) {
- return m.e2tInstancesManager.RemoveRanFromInstance(nodebInfo.RanName, e2tAddress)
+ return m.e2tAssociationManager.DissociateRan(e2tAddress, nodebInfo.RanName)
}
return nil
diff --git a/E2Manager/managers/ran_reconnection_manager_test.go b/E2Manager/managers/ran_reconnection_manager_test.go
index 44a3c78..e5e7ef3 100644
--- a/E2Manager/managers/ran_reconnection_manager_test.go
+++ b/E2Manager/managers/ran_reconnection_manager_test.go
@@ -21,6 +21,7 @@
package managers
import (
+ "e2mgr/clients"
"e2mgr/configuration"
"e2mgr/logger"
"e2mgr/mocks"
@@ -36,7 +37,7 @@
"testing"
)
-func initRanLostConnectionTest(t *testing.T) (*logger.Logger, *mocks.RmrMessengerMock, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager) {
+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 {
t.Errorf("#... - failed to initialize logger, error: %s", err)
@@ -53,33 +54,15 @@
rnibDataService := services.NewRnibDataService(logger, config, readerMock, writerMock)
e2tInstancesManager := NewE2TInstancesManager(rnibDataService, logger)
ranSetupManager := NewRanSetupManager(logger, rmrSender, rnibDataService)
- ranReconnectionManager := NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManager)
- return logger, rmrMessengerMock, readerMock, writerMock, ranReconnectionManager
-}
-
-func initRanLostConnectionTestBasicMocks(t *testing.T) (*logger.Logger, *mocks.RmrMessengerMock, *mocks.RnibReaderMock, *mocks.RnibWriterMock, *RanReconnectionManager, *mocks.E2TInstancesManagerMock) {
- logger, err := logger.InitLogger(logger.DebugLevel)
- if err != nil {
- t.Errorf("#... - failed to initialize logger, error: %s", err)
- }
- 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)
- e2tInstancesManagerMock := &mocks.E2TInstancesManagerMock{}
- ranSetupManager := NewRanSetupManager(logger, rmrSender, rnibDataService)
- ranReconnectionManager := NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManagerMock)
- return logger, rmrMessengerMock, readerMock, writerMock, ranReconnectionManager, e2tInstancesManagerMock
+ httpClient := &mocks.HttpClientMock{}
+ routingManagerClient := clients.NewRoutingManagerClient(logger, config, httpClient)
+ e2tAssociationManager := NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient)
+ ranReconnectionManager := NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tAssociationManager)
+ return logger, rmrMessengerMock, readerMock, writerMock, ranReconnectionManager, httpClient
}
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")))
@@ -90,7 +73,7 @@
}
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 error
@@ -102,7 +85,7 @@
}
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 error
@@ -117,29 +100,29 @@
}
func TestConnectingRanWithMaxAttemptsReconnectionDissociateSucceeds(t *testing.T) {
- _, _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(t)
+ _, _, readerMock, writerMock, ranReconnectionManager, httpClient:= 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}
+ 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)
+ 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, true)
err := ranReconnectionManager.ReconnectRan(ranName)
assert.Nil(t, err)
readerMock.AssertCalled(t, "GetNodeb", ranName)
- writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 1)
+ writerMock.AssertNumberOfCalls(t, "UpdateNodebInfo", 2)
}
func TestConnectingRanWithMaxAttemptsReconnectionDissociateFails(t *testing.T) {
- _, _, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(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}
@@ -154,12 +137,12 @@
err := ranReconnectionManager.ReconnectRan(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 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 error
@@ -174,7 +157,7 @@
}
func TestConnectedRanExecuteSetupSuccess(t *testing.T) {
- _, rmrMessengerMock, readerMock, writerMock, ranReconnectionManager := initRanLostConnectionTest(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
@@ -192,7 +175,7 @@
}
func TestConnectedRanExecuteSetupFailure(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_CONNECTED}
var rnibErr error
@@ -208,7 +191,7 @@
}
func TestNoSetConnectionStatus(t *testing.T) {
- _, _, _, _, ranReconnectionManager := initRanLostConnectionTest(t)
+ _, _, _, _, ranReconnectionManager, _ := initRanLostConnectionTest(t)
nodebInfo := &entities.NodebInfo{RanName: "ranName", GlobalNbId: &entities.GlobalNbId{PlmnId: "xxx", NbId: "yyy"}, ConnectionStatus: entities.ConnectionStatus_CONNECTED}
err := ranReconnectionManager.updateUnconnectableRan(nodebInfo)
assert.Nil(t, err)
diff --git a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go
index b7002ad..3d79c28 100644
--- a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go
+++ b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider.go
@@ -58,7 +58,7 @@
provider.notificationHandlers[msgType] = handler
}
-func (provider *NotificationHandlerProvider) Init(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, ranSetupManager *managers.RanSetupManager, e2tInstancesManager managers.IE2TInstancesManager, routingManagerClient clients.IRoutingManagerClient) {
+func (provider *NotificationHandlerProvider) Init(logger *logger.Logger, config *configuration.Configuration, rnibDataService services.RNibDataService, rmrSender *rmrsender.RmrSender, ranSetupManager *managers.RanSetupManager, e2tInstancesManager managers.IE2TInstancesManager, routingManagerClient clients.IRoutingManagerClient, e2tAssociationManager *managers.E2TAssociationManager) {
// Init converters
x2SetupResponseConverter := converters.NewX2SetupResponseConverter(logger)
@@ -69,7 +69,7 @@
x2ResetResponseExtractor := converters.NewX2ResetResponseExtractor(logger)
// Init managers
- ranReconnectionManager := managers.NewRanReconnectionManager(logger, config, rnibDataService, ranSetupManager, e2tInstancesManager)
+ ranReconnectionManager := managers.NewRanReconnectionManager(logger, config, rnibDataService, ranSetupManager, e2tAssociationManager)
ranStatusChangeManager := managers.NewRanStatusChangeManager(logger, rmrSender)
x2SetupResponseManager := managers.NewX2SetupResponseManager(x2SetupResponseConverter)
x2SetupFailureResponseManager := managers.NewX2SetupFailureResponseManager(x2SetupFailureResponseConverter)
diff --git a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go
index d01d7c4..5d20a5f 100644
--- a/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go
+++ b/E2Manager/providers/rmrmsghandlerprovider/notification_handler_provider_test.go
@@ -42,7 +42,7 @@
* Verify support for known providers.
*/
-func initTestCase(t *testing.T) (*logger.Logger, *configuration.Configuration, services.RNibDataService, *rmrsender.RmrSender, *managers.RanSetupManager, managers.IE2TInstancesManager, clients.IRoutingManagerClient) {
+func initTestCase(t *testing.T) (*logger.Logger, *configuration.Configuration, services.RNibDataService, *rmrsender.RmrSender, *managers.RanSetupManager, managers.IE2TInstancesManager, clients.IRoutingManagerClient, *managers.E2TAssociationManager) {
logger := initLog(t)
config := &configuration.Configuration{RnibRetryIntervalMs: 10, MaxRnibConnectionAttempts: 3}
@@ -55,15 +55,16 @@
ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService)
e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger)
routingManagerClient := clients.NewRoutingManagerClient(logger, config, httpClient)
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient)
- return logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient
+ return logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager
}
func TestGetNotificationHandlerSuccess(t *testing.T) {
- logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient := initTestCase(t)
+ logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager := initTestCase(t)
- ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tInstancesManager)
+ ranReconnectionManager := managers.NewRanReconnectionManager(logger, configuration.ParseConfiguration(), rnibDataService, ranSetupManager, e2tAssociationManager)
ranStatusChangeManager := managers.NewRanStatusChangeManager(logger, rmrSender)
x2SetupResponseConverter := converters.NewX2SetupResponseConverter(logger)
@@ -101,7 +102,7 @@
for _, tc := range testCases {
provider := NewNotificationHandlerProvider()
- provider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient)
+ provider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager)
t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
handler, err := provider.GetNotificationHandler(tc.msgType)
if err != nil {
@@ -130,9 +131,9 @@
}
for _, tc := range testCases {
- logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient := initTestCase(t)
+ logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager := initTestCase(t)
provider := NewNotificationHandlerProvider()
- provider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient)
+ provider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager)
t.Run(fmt.Sprintf("%d", tc.msgType), func(t *testing.T) {
_, err := provider.GetNotificationHandler(tc.msgType)
if err == nil {
diff --git a/E2Manager/services/rmrreceiver/rmr_receiver_test.go b/E2Manager/services/rmrreceiver/rmr_receiver_test.go
index 5e766f7..b79c581 100644
--- a/E2Manager/services/rmrreceiver/rmr_receiver_test.go
+++ b/E2Manager/services/rmrreceiver/rmr_receiver_test.go
@@ -72,8 +72,9 @@
ranSetupManager := managers.NewRanSetupManager(logger, rmrSender, rnibDataService)
e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, logger)
routingManagerClient := clients.NewRoutingManagerClient(logger, config, httpClient)
+ e2tAssociationManager := managers.NewE2TAssociationManager(logger, rnibDataService, e2tInstancesManager, routingManagerClient)
rmrNotificationHandlerProvider := rmrmsghandlerprovider.NewNotificationHandlerProvider()
- rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient)
+ rmrNotificationHandlerProvider.Init(logger, config, rnibDataService, rmrSender, ranSetupManager, e2tInstancesManager, routingManagerClient, e2tAssociationManager)
notificationManager := notificationmanager.NewNotificationManager(logger, rmrNotificationHandlerProvider)
return NewRmrReceiver(logger, rmrMessenger, notificationManager)
}