From 9261ff6f1217ffbe74c04a1579c15835069f2df4 Mon Sep 17 00:00:00 2001 From: Mohamed Abukar Date: Fri, 20 Nov 2020 10:23:15 +0200 Subject: [PATCH] Parse messaging section Change-Id: I0398c3b83316b40891d33661b79d73f384a4c59f Signed-off-by: Mohamed Abukar --- container-tag.yaml | 2 +- pkg/cm/cm.go | 38 +++++++++++++----- pkg/cm/cm_test.go | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 11 deletions(-) diff --git a/container-tag.yaml b/container-tag.yaml index b923492..643454e 100755 --- a/container-tag.yaml +++ b/container-tag.yaml @@ -1,4 +1,4 @@ # The Jenkins job uses this string for the tag in the image name # for example nexus3.o-ran-sc.org:10004/my-image-name:my-tag --- -tag: '0.5.0' +tag: '0.5.1' diff --git a/pkg/cm/cm.go b/pkg/cm/cm.go index 9857e00..6200180 100755 --- a/pkg/cm/cm.go +++ b/pkg/cm/cm.go @@ -227,20 +227,38 @@ func (cm *CM) GetRtmData(name string) (msgs appmgr.RtmData) { return } - for _, m := range v.GetArray("rmr", "txMessages") { - msgs.TxMessages = append(msgs.TxMessages, strings.Trim(m.String(), `"`)) - } + if v.Exists("rmr") { + for _, m := range v.GetArray("rmr", "txMessages") { + msgs.TxMessages = append(msgs.TxMessages, strings.Trim(m.String(), `"`)) + } - for _, m := range v.GetArray("rmr", "rxMessages") { - msgs.RxMessages = append(msgs.RxMessages, strings.Trim(m.String(), `"`)) - } + for _, m := range v.GetArray("rmr", "rxMessages") { + msgs.RxMessages = append(msgs.RxMessages, strings.Trim(m.String(), `"`)) + } - for _, m := range v.GetArray("rmr", "policies") { - if val, err := strconv.Atoi(strings.Trim(m.String(), `"`)); err == nil { - msgs.Policies = append(msgs.Policies, int64(val)) + for _, m := range v.GetArray("rmr", "policies") { + if val, err := strconv.Atoi(strings.Trim(m.String(), `"`)); err == nil { + msgs.Policies = append(msgs.Policies, int64(val)) + } } - } + } else { + for _, p := range v.GetArray("messaging", "ports") { + appmgr.Logger.Info("txMessages=%v, rxMessages=%v", p.GetArray("txMessages"), p.GetArray("rxMessages")) + for _, m := range p.GetArray("txMessages") { + msgs.TxMessages = append(msgs.TxMessages, strings.Trim(m.String(), `"`)) + } + + for _, m := range p.GetArray("rxMessages") { + msgs.RxMessages = append(msgs.RxMessages, strings.Trim(m.String(), `"`)) + } + for _, m := range p.GetArray("policies") { + if val, err := strconv.Atoi(strings.Trim(m.String(), `"`)); err == nil { + msgs.Policies = append(msgs.Policies, int64(val)) + } + } + } + } return } diff --git a/pkg/cm/cm_test.go b/pkg/cm/cm_test.go index b180fc9..6c98645 100755 --- a/pkg/cm/cm_test.go +++ b/pkg/cm/cm_test.go @@ -83,6 +83,98 @@ var kubectlConfigmapOutput = ` } } ` +var kubectlNewConfigmapOutput = ` +{ + "name": "ueec", + "version": "0.7.0", + "vendor": "Nokia", + "moId": "SEP", + "containers": [ + { + "name": "ueec", + "image": { + "registry": "ranco-dev-tools.eastus.cloudapp.azure.com:10001", + "name": "ueec-xapp", + "tag": "0.5.3" + }, + "resources": { + "limits": { + "cpu": "1", + "memory": "50Mi" + }, + "requests": { + "cpu": "1", + "memory": "100Mi" + } + } + } + ], + "livenessProbe": { + "httpGet": { + "path": "ric/v1/health/alive", + "port": 8080 + }, + "initialDelaySeconds": 5, + "periodSeconds": 15 + }, + "readinessProbe": { + "httpGet": { + "path": "ric/v1/health/ready", + "port": 8080 + }, + "initialDelaySeconds": 5, + "periodSeconds": 15 + }, + "messaging": { + "ports": [ + { + "name": "http", + "container": "ueec", + "port": 8080, + "description": "http service" + }, + { + "name": "rmr-route", + "container": "ueec", + "port": 4561, + "description": "rmr route port for ueec" + }, + { + "name": "rmr-data", + "container": "ueec", + "port": 4560, + "maxSize": 2072, + "threadType": 0, + "lowLatency": false, + "txMessages": ["RIC_X2_LOAD_INFORMATION"], + "rxMessages": ["RIC_X2_LOAD_INFORMATION"], + "policies": [11, 22, 33], + "description": "rmr data port for ueec" + } + ] + }, + "controls": { + "logger": { + "level": 3 + }, + "subscription": { + "subscriptionActive": true, + "functionId": 1, + "plmnId": "310150", + "eNBId": "202251", + "timeout": 5, + "host": "service-ricplt-submgr-http.ricplt:8088", + "clientEndpoint": "service-ricxapp-ueec-http.ricxapp:8080" + } + }, + "metrics": { + "url": "/ric/v1/metrics", + "namespace": "ricxapp" + }, + "faults": { }, + "measurements": [] +} +` var cfgData = `{ "active":true, "interfaceId": { @@ -293,6 +385,30 @@ func TestGetRtmDataSuccess(t *testing.T) { } } +func TestGetRtmDataNewSuccess(t *testing.T) { + expectedKubeCmd := []string{ + `get configmap -o jsonpath='{.data.config-file\.json}' -n ricxapp configmap-ricxapp-dummy-xapp-appconfig`, + } + expectedMsgs := appmgr.RtmData{ + TxMessages: []string{"RIC_X2_LOAD_INFORMATION"}, + RxMessages: []string{"RIC_X2_LOAD_INFORMATION"}, + Policies: []int64{11, 22, 33}, + } + + defer func() { resetKubeExecMock() }() + kubeExec = mockedKubeExec + //Fake 'kubectl get configmap' success + kubeExecRetOut = kubectlNewConfigmapOutput + + result := NewCM().GetRtmData("dummy-xapp") + if !reflect.DeepEqual(result, expectedMsgs) { + t.Errorf("GetRtmData failed: expected: %v, got: %v", expectedMsgs, result) + } + if !reflect.DeepEqual(caughtKubeExecArgs, expectedKubeCmd) { + t.Errorf("GetRtmData failed: expected: '%v', got: '%v'", expectedKubeCmd, caughtKubeExecArgs) + } +} + func TestGetRtmDataReturnsNoDataIfConfigmapGetFails(t *testing.T) { var expectedMsgs appmgr.RtmData -- 2.16.6