Merge "Fix license headers"
authorShuky Har-Noy <shuky.har-noy@intl.att.com>
Wed, 25 Dec 2019 08:32:34 +0000 (08:32 +0000)
committerGerrit Code Review <gerrit@o-ran-sc.org>
Wed, 25 Dec 2019 08:32:34 +0000 (08:32 +0000)
Automation/Tests/Get_E2T_Instances/get_e2t_instances.robot [new file with mode: 0644]
Automation/Tests/Unhappy/Get_E2T_Instances_DB_Error.robot [new file with mode: 0644]
E2Manager/clients/routing_manager_client.go
E2Manager/clients/routing_manager_client_test.go
E2Manager/controllers/e2t_controller.go
E2Manager/controllers/e2t_controller_test.go [new file with mode: 0644]
E2Manager/controllers/nodeb_controller.go
E2Manager/go.mod
E2Manager/handlers/httpmsghandlers/setup_request_handler_test.go
E2Manager/managers/e2t_association_manager_test.go
E2Manager/models/routing_manager_e2t_data_list.go [new file with mode: 0644]

diff --git a/Automation/Tests/Get_E2T_Instances/get_e2t_instances.robot b/Automation/Tests/Get_E2T_Instances/get_e2t_instances.robot
new file mode 100644 (file)
index 0000000..dbafcfc
--- /dev/null
@@ -0,0 +1,59 @@
+##############################################################################
+#
+#   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.
+#
+##############################################################################
+
+*** Settings ***
+Suite Setup   Prepare Enviorment
+Resource   ../Resource/Keywords.robot
+Resource   ../Resource/resource.robot
+Library     REST      ${url}
+Library    RequestsLibrary
+Library    Collections
+Library    OperatingSystem
+Library    json
+
+
+*** Test Cases ***
+
+Get E2T instances 1st call
+    Create Session  getE2tInstances  ${url}
+    ${headers}=  Create Dictionary    Accept=application/json
+    ${resp}=    Get Request   getE2tInstances     /v1/e2t/list    headers=${headers}
+    Should Be Equal As Strings   ${resp.status_code}    200
+    Should Be Equal As Strings    ${resp.content}        [{"e2tAddress":"e2t.att.com:38000","ranNames":[]}]
+
+Get E2T instances after one setup
+
+    Post Request setup node b x-2
+    Integer     response status       204
+    Create Session  getE2tInstances  ${url}
+    ${headers}=  Create Dictionary    Accept=application/json
+    ${resp}=    Get Request   getE2tInstances     /v1/e2t/list    headers=${headers}
+    Should Be Equal As Strings   ${resp.status_code}    200
+    Should Be Equal As Strings    ${resp.content}        [{\"e2tAddress\":\"e2t.att.com:38000\",\"ranNames\":[\"test1\"]}]
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Automation/Tests/Unhappy/Get_E2T_Instances_DB_Error.robot b/Automation/Tests/Unhappy/Get_E2T_Instances_DB_Error.robot
new file mode 100644 (file)
index 0000000..9ab940f
--- /dev/null
@@ -0,0 +1,32 @@
+##############################################################################
+#
+#   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.
+#
+##############################################################################
+
+*** Settings ***
+Suite Setup   Prepare Enviorment
+Resource   ../Resource/Keywords.robot
+Resource   ../Resource/resource.robot
+Library     REST      ${url}
+Suite Teardown   Start Dbass
+
+*** Test Cases ***
+Get All E2T Instances DB Error - 500
+    Stop Dbass
+    GET      /v1/e2t/list
+    Integer  response status            500
+    Integer  response body errorCode            500
+    String   response body errorMessage     RNIB error
\ No newline at end of file
index c584f5b..52e9250 100644 (file)
@@ -65,7 +65,7 @@ func (c *RoutingManagerClient) AddE2TInstance(e2tAddress string) error {
 
 func (c *RoutingManagerClient) AssociateRanToE2TInstance(e2tAddress string, ranName string) error {
 
-       data := models.NewRoutingManagerE2TData(e2tAddress, ranName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(e2tAddress, ranName)}
        url := c.config.RoutingManager.BaseUrl + AssociateRanToE2TInstanceApiSuffix
 
        return c.PostMessage(data, url)
@@ -73,13 +73,21 @@ func (c *RoutingManagerClient) AssociateRanToE2TInstance(e2tAddress string, ranN
 
 func (c *RoutingManagerClient) DissociateRanE2TInstance(e2tAddress string, ranName string) error {
 
-       data := models.NewRoutingManagerE2TData(e2tAddress, ranName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(e2tAddress, ranName)}
        url := c.config.RoutingManager.BaseUrl + DissociateRanE2TInstanceApiSuffix
 
        return c.PostMessage(data, url)
 }
 
-func (c *RoutingManagerClient) PostMessage(data *models.RoutingManagerE2TData, url string) error {
+func (c *RoutingManagerClient) DissociateAllRans(e2tAddresses []string) error {
+
+       data := mapE2TAddressesToE2DataList(e2tAddresses)
+       url := c.config.RoutingManager.BaseUrl + DissociateRanE2TInstanceApiSuffix
+
+       return c.PostMessage(data, url)
+}
+
+func (c *RoutingManagerClient) PostMessage(data interface{}, url string) error {
        marshaled, err := json.Marshal(data)
 
        if err != nil {
@@ -105,4 +113,14 @@ func (c *RoutingManagerClient) PostMessage(data *models.RoutingManagerE2TData, u
 
        c.logger.Errorf("[Routing Manager -> E2M] #RoutingManagerClient.PostMessage - failure. http status code: %d", resp.StatusCode)
        return e2managererrors.NewRoutingManagerError()
-}
\ No newline at end of file
+}
+
+func mapE2TAddressesToE2DataList(e2tAddresses []string) models.RoutingManagerE2TDataList {
+       e2tDataList := make(models.RoutingManagerE2TDataList, len(e2tAddresses))
+
+       for i, v := range e2tAddresses {
+               e2tDataList[i] = models.NewRoutingManagerE2TData(v)
+       }
+
+       return e2tDataList
+}
index 2d02cfd..59e6125 100644 (file)
@@ -88,7 +88,7 @@ func TestAddE2TInstanceFailure(t *testing.T) {
 func TestAssociateRanToE2TInstance_Success(t *testing.T) {
        rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
 
-       data := models.NewRoutingManagerE2TData(E2TAddress,RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress,RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := config.RoutingManager.BaseUrl + AssociateRanToE2TInstanceApiSuffix
@@ -101,7 +101,7 @@ func TestAssociateRanToE2TInstance_Success(t *testing.T) {
 func TestAssociateRanToE2TInstance_RoutingManagerError(t *testing.T) {
        rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
 
-       data := models.NewRoutingManagerE2TData(E2TAddress,RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress,RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := config.RoutingManager.BaseUrl + AssociateRanToE2TInstanceApiSuffix
@@ -113,7 +113,7 @@ func TestAssociateRanToE2TInstance_RoutingManagerError(t *testing.T) {
 func TestAssociateRanToE2TInstance_RoutingManager_400(t *testing.T) {
        rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
 
-       data := models.NewRoutingManagerE2TData(E2TAddress,RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress,RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := config.RoutingManager.BaseUrl + AssociateRanToE2TInstanceApiSuffix
@@ -126,7 +126,7 @@ func TestAssociateRanToE2TInstance_RoutingManager_400(t *testing.T) {
 func TestDissociateRanE2TInstance_Success(t *testing.T) {
        rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
 
-       data := models.NewRoutingManagerE2TData(E2TAddress,RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress,RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := config.RoutingManager.BaseUrl + DissociateRanE2TInstanceApiSuffix
@@ -139,7 +139,7 @@ func TestDissociateRanE2TInstance_Success(t *testing.T) {
 func TestDissociateRanE2TInstance_RoutingManagerError(t *testing.T) {
        rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
 
-       data := models.NewRoutingManagerE2TData(E2TAddress,RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress,RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := config.RoutingManager.BaseUrl + DissociateRanE2TInstanceApiSuffix
@@ -151,7 +151,7 @@ func TestDissociateRanE2TInstance_RoutingManagerError(t *testing.T) {
 func TestDissociateRanE2TInstance_RoutingManager_400(t *testing.T) {
        rmClient, httpClientMock, config := initRoutingManagerClientTest(t)
 
-       data := models.NewRoutingManagerE2TData(E2TAddress,RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress,RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := config.RoutingManager.BaseUrl + DissociateRanE2TInstanceApiSuffix
index 01d89dc..5b1b38d 100644 (file)
@@ -69,12 +69,6 @@ func (c *E2TController) handleRequest(writer http.ResponseWriter, header *http.H
                return
        }
 
-       if response == nil {
-               writer.WriteHeader(http.StatusNoContent)
-               c.logger.Infof("[E2 Manager -> Client] #E2TController.handleRequest - status response: %v", http.StatusNoContent)
-               return
-       }
-
        result, err := response.Marshal()
 
        if err != nil {
@@ -112,10 +106,6 @@ func (c *E2TController) handleErrorResponse(err error, writer http.ResponseWrite
        writer.Header().Set("Content-Type", "application/json")
        writer.WriteHeader(httpError)
        _, err = writer.Write(errorResponse)
-
-       if err != nil {
-               c.logger.Errorf("#E2TController.handleErrorResponse - Cannot send response. writer:%v", writer)
-       }
 }
 
 func (c *E2TController) prettifyRequest(request *http.Request) string {
diff --git a/E2Manager/controllers/e2t_controller_test.go b/E2Manager/controllers/e2t_controller_test.go
new file mode 100644 (file)
index 0000000..1ed6934
--- /dev/null
@@ -0,0 +1,137 @@
+//
+// 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 controllers
+
+import (
+       "e2mgr/configuration"
+       "e2mgr/managers"
+       "e2mgr/mocks"
+       "e2mgr/models"
+       "e2mgr/providers/httpmsghandlerprovider"
+       "e2mgr/services"
+       "encoding/json"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/common"
+       "gerrit.o-ran-sc.org/r/ric-plt/nodeb-rnib.git/entities"
+       "github.com/magiconair/properties/assert"
+       "github.com/pkg/errors"
+       "io/ioutil"
+       "net/http"
+       "net/http/httptest"
+       "testing"
+)
+
+const E2TAddress string = "10.0.2.15:38000"
+const E2TAddress2 string = "10.0.2.16:38001"
+
+type controllerE2TInstancesTestContext struct {
+       e2tAddresses         []string
+       e2tInstances         []*entities.E2TInstance
+       error                error
+       expectedStatusCode   int
+       expectedJsonResponse string
+}
+
+func setupE2TControllerTest(t *testing.T) (*E2TController, *mocks.RnibReaderMock) {
+       log := initLog(t)
+       config := configuration.ParseConfiguration()
+
+       readerMock := &mocks.RnibReaderMock{}
+
+       rnibDataService := services.NewRnibDataService(log, config, readerMock, nil)
+       e2tInstancesManager := managers.NewE2TInstancesManager(rnibDataService, log)
+       handlerProvider := httpmsghandlerprovider.NewIncomingRequestHandlerProvider(log, nil, config, rnibDataService, nil, e2tInstancesManager, &managers.E2TAssociationManager{})
+       controller := NewE2TController(log, handlerProvider)
+       return controller, readerMock
+}
+
+func controllerGetE2TInstancesTestExecuter(t *testing.T, context *controllerE2TInstancesTestContext) {
+       controller, readerMock := setupE2TControllerTest(t)
+       writer := httptest.NewRecorder()
+       readerMock.On("GetE2TAddresses").Return(context.e2tAddresses, context.error)
+
+       if context.e2tInstances != nil {
+               readerMock.On("GetE2TInstances", context.e2tAddresses).Return(context.e2tInstances, context.error)
+       }
+
+       req, _ := http.NewRequest("GET", "/e2t/list", nil)
+       controller.GetE2TInstances(writer, req)
+       assert.Equal(t, context.expectedStatusCode, writer.Result().StatusCode)
+       bodyBytes, _ := ioutil.ReadAll(writer.Body)
+       assert.Equal(t, context.expectedJsonResponse, string(bodyBytes))
+       readerMock.AssertExpectations(t)
+}
+
+func TestControllerGetE2TInstancesSuccess(t *testing.T) {
+       ranNames1 := []string{"test1", "test2", "test3"}
+       e2tInstanceResponseModel1 := models.NewE2TInstanceResponseModel(E2TAddress, ranNames1)
+       e2tInstanceResponseModel2 := models.NewE2TInstanceResponseModel(E2TAddress2, []string{})
+       e2tInstancesResponse := models.E2TInstancesResponse{e2tInstanceResponseModel1, e2tInstanceResponseModel2}
+       bytes, _ := json.Marshal(e2tInstancesResponse)
+
+       context := controllerE2TInstancesTestContext{
+               e2tAddresses:         []string{E2TAddress, E2TAddress2},
+               e2tInstances:         []*entities.E2TInstance{{Address: E2TAddress, AssociatedRanList: ranNames1}, {Address: E2TAddress2, AssociatedRanList: []string{}}},
+               error:                nil,
+               expectedStatusCode:   http.StatusOK,
+               expectedJsonResponse: string(bytes),
+       }
+
+       controllerGetE2TInstancesTestExecuter(t, &context)
+}
+
+func TestControllerGetE2TInstancesEmptySuccess(t *testing.T) {
+       e2tInstancesResponse := models.E2TInstancesResponse{}
+       bytes, _ := json.Marshal(e2tInstancesResponse)
+
+       context := controllerE2TInstancesTestContext{
+               e2tAddresses:         []string{},
+               e2tInstances:         nil,
+               error:                nil,
+               expectedStatusCode:   http.StatusOK,
+               expectedJsonResponse: string(bytes),
+       }
+
+       controllerGetE2TInstancesTestExecuter(t, &context)
+}
+
+func TestControllerGetE2TInstancesInternal(t *testing.T) {
+       context := controllerE2TInstancesTestContext{
+               e2tAddresses:         nil,
+               e2tInstances:         nil,
+               error:                common.NewInternalError(errors.New("error")),
+               expectedStatusCode:   http.StatusInternalServerError,
+               expectedJsonResponse: "{\"errorCode\":500,\"errorMessage\":\"RNIB error\"}",
+       }
+
+       controllerGetE2TInstancesTestExecuter(t, &context)
+}
+
+func TestInvalidRequestName(t *testing.T) {
+       controller, _ := setupE2TControllerTest(t)
+
+       writer := httptest.NewRecorder()
+
+       header := &http.Header{}
+
+       controller.handleRequest(writer, header, "", nil, true)
+
+       var errorResponse = parseJsonRequest(t, writer.Body)
+
+       assert.Equal(t, http.StatusInternalServerError, writer.Result().StatusCode)
+       assert.Equal(t, errorResponse.Code, 501)
+}
index 8b8c743..7b8a86f 100644 (file)
@@ -249,10 +249,6 @@ func (c *NodebController) handleErrorResponse(err error, writer http.ResponseWri
        writer.Header().Set("Content-Type", "application/json")
        writer.WriteHeader(httpError)
        _, err = writer.Write(errorResponse)
-
-       if err != nil {
-               c.logger.Errorf("#NodebController.handleErrorResponse - Cannot send response. writer:%v", writer)
-       }
 }
 
 func (c *NodebController) prettifyRequest(request *http.Request) string {
index 1fd1095..7d2e125 100644 (file)
@@ -9,7 +9,7 @@ require (
        github.com/go-ozzo/ozzo-validation v3.5.0+incompatible
        github.com/golang/protobuf v1.3.2
        github.com/gorilla/mux v1.7.0
-       github.com/magiconair/properties v1.8.1 // indirect
+       github.com/magiconair/properties v1.8.1
        github.com/pelletier/go-toml v1.5.0 // indirect
        github.com/pkg/errors v0.8.1
        github.com/spf13/afero v1.2.2 // indirect
index 2fc1c5c..7586791 100644 (file)
@@ -88,7 +88,7 @@ func initSetupRequestTestBasicMocks(t *testing.T, protocol entities.E2Applicatio
 }
 
 func mockHttpClientAssociateRan(httpClientMock *mocks.HttpClientMock) {
-       data := models.NewRoutingManagerE2TData(E2TAddress, RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress, RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := BaseRMUrl + clients.AssociateRanToE2TInstanceApiSuffix
index 75cfb3b..6754a3b 100644 (file)
@@ -57,7 +57,7 @@ func initE2TAssociationManagerTest(t *testing.T) (*E2TAssociationManager, *mocks
 }
 
 func mockHttpClientAssociateRan(httpClientMock *mocks.HttpClientMock, isSuccessful bool) {
-       data := models.NewRoutingManagerE2TData(E2TAddress, RanName)
+       data := models.RoutingManagerE2TDataList{models.NewRoutingManagerE2TData(E2TAddress, RanName)}
        marshaled, _ := json.Marshal(data)
        body := bytes.NewBuffer(marshaled)
        url := BaseRMUrl + clients.AssociateRanToE2TInstanceApiSuffix
diff --git a/E2Manager/models/routing_manager_e2t_data_list.go b/E2Manager/models/routing_manager_e2t_data_list.go
new file mode 100644 (file)
index 0000000..4179d83
--- /dev/null
@@ -0,0 +1,22 @@
+//
+// 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.
+
+//  This source code is part of the near-RT RIC (RAN Intelligent Controller)
+//  platform project (RICP).
+
+package models
+
+type RoutingManagerE2TDataList []*RoutingManagerE2TData