API to return RanfunctionDefinition for particular RanfunctionOID 11/7911/4
authormanoj1 <manoj.1.manoj@nokia.com>
Mon, 7 Mar 2022 09:58:27 +0000 (04:58 -0500)
committerManoj Manoj <manoj.1.manoj@nokia.com>
Fri, 11 Mar 2022 09:28:21 +0000 (09:28 +0000)
Change-Id: Ieaf679060051138b91b8af6270041959bd3a6114
Signed-off-by: manoj1 <manoj.1.manoj@nokia.com>
reader/rNibReader.go
reader/rNibReader_test.go

index 77fee8d..c12a2c8 100644 (file)
@@ -67,6 +67,8 @@ type RNibReader interface {
        GetE2TAddresses() ([]string, error)
 
        GetGeneralConfiguration() (*entities.GeneralConfiguration, error)
+
+        GetRanFunctionDefinition(inventoryName string, Oid string) ([]string, error)
 }
 
 //GetNewRNibReader returns reference to RNibReader
@@ -78,6 +80,22 @@ func GetNewRNibReader(storage common.ISdlSyncStorage) RNibReader {
        }
 }
 
+//GetRanFunctionDefinition from the OID
+func (w *rNibReaderInstance) GetRanFunctionDefinition(inventoryName string, oid string) ([]string, error){
+    nb, err := w.GetNodeb (inventoryName)
+    if (nb.GetGnb() != nil) {
+        ranFunction := nb.GetGnb().RanFunctions
+        functionDefinitionList := make([]string, 0)
+        for _, ranFunction := range ranFunction {
+            if (oid == ranFunction.RanFunctionOid) {
+                functionDefinitionList = append(functionDefinitionList ,ranFunction.RanFunctionDefinition)
+                }
+        }
+        return functionDefinitionList, err
+    }
+    return nil, common.NewResourceNotFoundErrorf("#rNibReader.GetCellList - served cells not found. Responding node RAN name: %    s.", inventoryName)
+}
+
 //GetRNibReader returns reference to RNibReader
 //Deprecated: Will be removed in a future release, please use GetNewRNibReader instead.
 func GetRNibReader(sdl common.ISdlInstance) RNibReader {
index caf35e3..3007b33 100644 (file)
@@ -1243,6 +1243,34 @@ func TestGetGeneralConfigurationUnmarshalError(t *testing.T) {
        assert.Equal(t, rNibErr.Error(), "unexpected end of JSON input")
 }
 
+func TestGetRanFunctionDefinition(t *testing.T) {
+    name := "name"
+    oid := "1.3.6.1.4.1.1.2.2.2"
+    w, sdlInstanceMock := initSdlSyncStorageMock()
+    nb := entities.NodebInfo{}
+    nb.ConnectionStatus = 1
+    nb.Ip = "localhost"
+    nb.Port = 5656
+    enb := entities.Enb{}
+    cell := entities.ServedCellInfo{Tac: "tac"}
+    enb.ServedCells = []*entities.ServedCellInfo{&cell}
+    nb.Configuration = &entities.NodebInfo_Enb{Enb: &enb}
+    var e error
+    data, err := proto.Marshal(&nb)
+    if err != nil {
+        t.Errorf("#rNibReader_test.GetRanFunctionDefinition - Failed to marshal ENB instance. Error: %v", err)
+    }
+    redisKey, rNibErr := common.ValidateAndBuildNodeBNameKey(name)
+    if rNibErr != nil {
+        t.Errorf("#rNibReader_test.TestRanFunctionDefinition - failed to validate key parameter")
+    }
+    ret := map[string]interface{}{redisKey: string(data)}
+    sdlInstanceMock.On("Get", common.GetRNibNamespace(), []string{redisKey}).Return(ret, e)
+    ranFuncs, er := w.GetRanFunctionDefinition(name, oid)
+    assert.IsType(t, &common.ResourceNotFoundError{}, er)
+    assert.Nil(t, ranFuncs)
+}
+
 //integration tests
 //
 //func TestGetEnbInteg(t *testing.T){