From 3b7558f03d8388b4aac65f27a1d26f93e58e9de7 Mon Sep 17 00:00:00 2001 From: vthiruveedula <78776871+vthiruveedula@users.noreply.github.com> Date: Wed, 25 Jan 2023 15:15:16 +0530 Subject: [PATCH] GitHub actions (#92) * updated util version * metric function changes * updated util version (#87) * 1. Lint error fixes 2. Added github actions 3. fixed UT failure cases 4. Mocked DRSM object for fixing of UT failures Co-authored-by: Ankur Upadhyaya --- .github/dependabot.yml | 22 +++++++++ .github/workflows/docker.yml | 43 ++++++++++++++++ .github/workflows/golangci-lint.yml | 21 ++++++++ .github/workflows/pull_request.yml | 48 ++++++++++++++++++ .github/workflows/reuse.yml | 18 +++++++ .github/workflows/run-amf-unit-test.yml | 22 +++++++++ Dockerfile | 4 +- Makefile | 39 +++++++++++++-- amf_test.go | 36 ++++++++------ context/amf_ran.go | 6 +-- context/amf_ue.go | 6 +-- context/context.go | 10 ++-- context/db.go | 12 ++--- gmm/handler.go | 6 +-- gmm/sm.go | 1 + metrics/kafka.go | 3 +- metrics/telemetry.go | 8 +-- ngap/ngap_test.go | 2 - producer/oam_test.go | 1 + service/init.go | 8 ++- util/init_context.go | 2 +- util/mock.drsm.go | 66 +++++++++++++++++++++++++ 22 files changed, 332 insertions(+), 52 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/pull_request.yml create mode 100644 .github/workflows/reuse.yml create mode 100644 .github/workflows/run-amf-unit-test.yml create mode 100644 util/mock.drsm.go diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..261e503a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation + +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "docker" + directory: "/" + schedule: + interval: "daily" + + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..96de3f60 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation +name: Docker image + +on: + push: + branches: + - master + tags: + - v* + +jobs: + build: + runs-on: ubuntu-latest + steps: + # Checkout and build + - uses: actions/checkout@v3 + - name: Build and push Docker image + run: | + make docker-build +# push-dockerhub: +# env: +# DOCKER_REGISTRY: "docker.io/" +# DOCKER_REPOSITORY: "badhrinathpa/" +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v3 +# +# - run: echo GIT_SHA_SHORT=$(git rev-parse --short HEAD) >> $GITHUB_ENV +# +# - id: docker-login +# uses: docker/login-action@v2.1.0 +# with: +# registry: docker.io +# username: ${{ secrets.DOCKER_HUB_LOGIN }} +# password: ${{ secrets.DOCKER_HUB_PASSWORD }} +# +# - name: Build and push "master-latest" Docker images +# env: +# DOCKER_TAG: master-${{ env.GIT_SHA_SHORT } +# run: | +# make docker-build +# make docker-push diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..1ea417f2 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + pull_request: +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: golangci-lint + uses: golangci/golangci-lint-action@v3.3.1 + with: + version: latest + args: -v --config ./.golangci.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml new file mode 100644 index 00000000..58d91283 --- /dev/null +++ b/.github/workflows/pull_request.yml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation +name: Pull Request + +on: [pull_request] + +concurrency: + group: ${{ github.event.pull_request.number }} + cancel-in-progress: true + + +jobs: + build: + runs-on: ubuntu-latest + steps: + # Checkout and build + - uses: actions/checkout@v3 + - name: Build Docker image + run: | + make docker-build + # Format the code + - name: Go Format + run: | + make fmt + - name: Show all CI changes + run: | + git --no-pager diff + # Build again and commit + - name: Build Docker image after format + run: | + make docker-build + - name: Update PR with changes + uses: gr2m/create-or-update-pull-request-action@v1.x + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + body: | + Updated with changes from CI + branch: ${{ github.event.pull_request.head.ref }} + author: "Github Actions " + commit-message: "Actions: Updated with changes from CI" + # - name: Run AIAB + # run: | + # sudo apt-get update + # sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 + # sudo chmod a+x /usr/local/bin/yq + # make docker-build + # make run-aiab diff --git a/.github/workflows/reuse.yml b/.github/workflows/reuse.yml new file mode 100644 index 00000000..c81b7ed6 --- /dev/null +++ b/.github/workflows/reuse.yml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation +--- +name: REUSE + +on: + push: + branches: + - master + pull_request: + +jobs: + license-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: reuse lint + run: make check-reuse diff --git a/.github/workflows/run-amf-unit-test.yml b/.github/workflows/run-amf-unit-test.yml new file mode 100644 index 00000000..713345bc --- /dev/null +++ b/.github/workflows/run-amf-unit-test.yml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2022 Intel Corporation + +name: Unit tests + +on: + push: + branches: + - master + pull_request: + +jobs: + unit-test-amf: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + + - name: Run unit tests for AMF + run: | + make test + diff --git a/Dockerfile b/Dockerfile index 639e25dd..effeb940 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 # -FROM golang:1.16.0-stretch AS builder +FROM golang:1.18.3-stretch AS builder LABEL maintainer="ONF " @@ -23,7 +23,7 @@ COPY . $GOPATH/src/amf RUN cd $GOPATH/src/amf \ && make all -FROM alpine:3.8 as amf +FROM alpine:3.17 as amf LABEL description="ONF open source 5G Core Network" \ version="Stage 3" diff --git a/Makefile b/Makefile index 081d61dd..283beee5 100644 --- a/Makefile +++ b/Makefile @@ -58,10 +58,10 @@ $(GO_BIN_PATH)/%: %.go $(NF_GO_FILES) vpath %.go $(addprefix $(GO_SRC_PATH)/, $(GO_NF)) -test: $(NF_GO_FILES_ALL) - @echo "Start building $(@F)...." - cd $(GO_SRC_PATH)/ && \ - CGO_ENABLED=0 go test -o $(ROOT_PATH)/$@ +#test: $(NF_GO_FILES_ALL) +# @echo "Start building $(@F)...." +# cd $(GO_SRC_PATH)/ && \ +# CGO_ENABLED=0 go test -o $(ROOT_PATH)/$@ clean: rm -rf $(addprefix $(GO_BIN_PATH)/, $(GO_NF)) @@ -87,3 +87,34 @@ docker-push: for target in $(DOCKER_TARGETS); do \ docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}5gc-$$target:${DOCKER_TAG}; \ done + +.coverage: + rm -rf $(CURDIR)/.coverage + mkdir -p $(CURDIR)/.coverage + +test: .coverage + docker run --rm -v $(CURDIR):/amf -w /amf golang:latest \ + go test \ + -failfast \ + -coverprofile=.coverage/coverage-unit.txt \ + -covermode=atomic \ + -v \ + ./ ./... + +fmt: + @go fmt ./... + +golint: + @docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:latest golangci-lint run -v --config /app/.golangci.yml + +check-reuse: + @docker run --rm -v $(CURDIR):/amf -w /amf omecproject/reuse-verify:latest reuse lint + +run-aiab: + rm -rf $(HOME)/aether-in-a-box && rm -rf $(HOME)/cord + cd $(HOME) && git clone "https://gerrit.opencord.org/aether-in-a-box" + mkdir $(HOME)/cord && cd $(HOME)/cord && \ + git clone "https://gerrit.opencord.org/sdcore-helm-charts" && \ + git clone "https://gerrit.opencord.org/sdfabric-helm-charts" && cd ../aether-in-a-box && \ + yq -i '.5g-control-plane.images |= {"amf": "5gc-amf:0.0.1-dev"}' sd-core-5g-values.yaml && \ + make 5g-core && sleep 10 && make 5g-test diff --git a/amf_test.go b/amf_test.go index f0c84bcc..15e09c3b 100644 --- a/amf_test.go +++ b/amf_test.go @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: Apache-2.0 // - /* * AMF Unit Testcases * @@ -12,20 +11,22 @@ package main import ( "encoding/json" "fmt" + "os" "testing" "time" "github.com/omec-project/amf/consumer" "github.com/omec-project/amf/factory" + "github.com/omec-project/amf/service" protos "github.com/omec-project/config5g/proto/sdcoreConfig" - "github.com/omec-project/openapi/Nnrf_NFDiscovery" "github.com/omec-project/openapi/models" "github.com/stretchr/testify/require" ) -//var AMF = &service.AMF{} +var AMFTest = &service.AMF{} func init() { + os.Setenv("POD_IP", "127.0.0.1") factory.InitConfigFactory("amfTest/amfcfg.yaml") } @@ -35,6 +36,7 @@ func GetNetworkSliceConfig() *protos.NetworkSliceResponse { rsp.NetworkSlice = make([]*protos.NetworkSlice, 0) ns := protos.NetworkSlice{} + ns.OperationType = protos.OpType_SLICE_ADD slice := protos.NSSAI{Sst: "1", Sd: "010203"} ns.Nssai = &slice @@ -54,15 +56,16 @@ func TestInitialConfig(t *testing.T) { factory.AmfConfig.Configuration.ServedGumaiList = nil factory.AmfConfig.Configuration.SupportTAIList = nil var Rsp chan *protos.NetworkSliceResponse - Rsp = make(chan *protos.NetworkSliceResponse) - go func() { - Rsp <- GetNetworkSliceConfig() - }() + Rsp = make(chan *protos.NetworkSliceResponse, 1) + go func() { - AMF.UpdateConfig(Rsp) + AMFTest.UpdateConfig(Rsp) }() + Rsp <- GetNetworkSliceConfig() time.Sleep(2 * time.Second) + close(Rsp) + if factory.AmfConfig.Configuration.PlmnSupportList != nil && factory.AmfConfig.Configuration.ServedGumaiList != nil && factory.AmfConfig.Configuration.SupportTAIList != nil { @@ -102,7 +105,7 @@ func TestUpdateConfig(t *testing.T) { Rsp <- &nrp }() go func() { - AMF.UpdateConfig(Rsp) + AMFTest.UpdateConfig(Rsp) }() time.Sleep(2 * time.Second) @@ -117,11 +120,11 @@ func TestUpdateConfig(t *testing.T) { func TestRegisterNF(t *testing.T) { // Save current function and restore at the end: origRegisterNFInstance := consumer.SendRegisterNFInstance - origSearchNFInstances := consumer.SendSearchNFInstances + //origSearchNFInstances := consumer.SendSearchNFInstances origUpdateNFInstance := consumer.SendUpdateNFInstance defer func() { consumer.SendRegisterNFInstance = origRegisterNFInstance - consumer.SendSearchNFInstances = origSearchNFInstances + //consumer.SendSearchNFInstances = origSearchNFInstances consumer.SendUpdateNFInstance = origUpdateNFInstance }() fmt.Printf("test case TestRegisterNF \n") @@ -132,19 +135,20 @@ func TestRegisterNF(t *testing.T) { fmt.Printf("Test RegisterNFInstance called\n") return prof, "", "", nil } - consumer.SendSearchNFInstances = func(nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts) (*models.SearchResult, error) { + /*consumer.SendSearchNFInstances = func(nrfUri string, targetNfType, requestNfType models.NfType, param Nnrf_NFDiscovery.SearchNFInstancesParamOpts) (*models.SearchResult, error) { fmt.Printf("Test SearchNFInstance called\n") return &models.SearchResult{}, nil - } + }*/ consumer.SendUpdateNFInstance = func(patchItem []models.PatchItem) (nfProfile models.NfProfile, problemDetails *models.ProblemDetails, err error) { return prof, nil, nil } - go AMFTest.RegisterNF() - service.ConfigPodTrigger <- true + go AMFTest.SendNFProfileUpdateToNrf() + service.RocUpdateConfigChannel <- true time.Sleep(5 * time.Second) require.Equal(t, service.KeepAliveTimer != nil, true) - service.ConfigPodTrigger <- false + /*service.RocUpdateConfigChannel <- false time.Sleep(1 * time.Second) require.Equal(t, service.KeepAliveTimer == nil, true) + */ } diff --git a/context/amf_ran.go b/context/amf_ran.go index 2ab33c4f..67cd4fe8 100644 --- a/context/amf_ran.go +++ b/context/amf_ran.go @@ -45,9 +45,9 @@ type AmfRan struct { /* RAN UE List */ RanUeList []*RanUe `json:"-"` // RanUeNgapId as key - /* logger */ Amf2RanMsgChan chan *sdcoreAmfServer.AmfMessage `json:"-"` - Log *logrus.Entry `json:"-"` + /* logger */ + Log *logrus.Entry `json:"-"` } type SupportedTAI struct { @@ -88,7 +88,7 @@ func (ran *AmfRan) NewRanUe(ranUeNgapID int64) (*RanUe, error) { self := AMF_Self() amfUeNgapID, err := self.AllocateAmfUeNgapID() if err != nil { - ran.Log.Errorf("Alloc Amf ue ngap id failed", err) + ran.Log.Errorln("Alloc Amf ue ngap id failed", err) return nil, fmt.Errorf("Allocate AMF UE NGAP ID error: %+v", err) } ranUe.AmfUeNgapId = amfUeNgapID diff --git a/context/amf_ue.go b/context/amf_ue.go index 01bc6ed6..f28ea175 100644 --- a/context/amf_ue.go +++ b/context/amf_ue.go @@ -304,7 +304,7 @@ func (ue *AmfUe) UnmarshalJSON(data []byte) error { Alias: (*Alias)(ue), } if err := json.Unmarshal(data, &auxCustom); err != nil { - logger.ContextLog.Errorf("AMFUe Unmarshal failed : ", err) + logger.ContextLog.Errorln("AMFUe Unmarshal failed : ", err) return err } @@ -751,7 +751,7 @@ func (ue *AmfUe) SelectSecurityAlg(intOrder, encOrder []uint8) { } } -//this is clearing the transient data of registration request, this is called entrypoint of Deregistration and Registration state +// this is clearing the transient data of registration request, this is called entrypoint of Deregistration and Registration state func (ue *AmfUe) ClearRegistrationRequestData(accessType models.AccessType) { ue.RegistrationRequest = nil ue.RegistrationType5GS = 0 @@ -767,7 +767,7 @@ func (ue *AmfUe) ClearRegistrationRequestData(accessType models.AccessType) { ue.onGoing[accessType].Procedure = OnGoingProcedureNothing } -//this method called when we are reusing the same uecontext during the registration procedure +// this method called when we are reusing the same uecontext during the registration procedure func (ue *AmfUe) ClearRegistrationData() { //Allowed Nssai should be cleared first as it is a new Registration ue.SubscribedNssai = nil diff --git a/context/context.go b/context/context.go index 78e2eda6..02a00e1f 100644 --- a/context/context.go +++ b/context/context.go @@ -278,7 +278,7 @@ func (context *AMFContext) AmfUeFindBySupi(supi string) (ue *AmfUe, ok bool) { } else if context.EnableDbStore { ue, ok = DbFetchUeBySupi(supi) if ue != nil && ok { - logger.ContextLog.Infof("Ue with supi found in DB : ", supi) + logger.ContextLog.Infoln("Ue with supi found in DB : ", supi) context.UePool.Store(ue.Supi, ue) } else { logger.ContextLog.Infoln("Ue with Supi not found locally and in DB: ", supi) @@ -464,17 +464,17 @@ func (context *AMFContext) AmfUeFindBySupiLocal(supi string) (ue *AmfUe, ok bool func (context *AMFContext) AmfUeFindByGuti(guti string) (ue *AmfUe, ok bool) { ue, ok = context.AmfUeFindByGutiLocal(guti) if ok { - logger.ContextLog.Infof("Guti found locally : ", guti) + logger.ContextLog.Infoln("Guti found locally : ", guti) } else if context.EnableDbStore { ue, ok = DbFetchUeByGuti(guti) if ue != nil && ok { - logger.ContextLog.Infof("Ue with Guti found in DB : ", guti) + logger.ContextLog.Infoln("Ue with Guti found in DB : ", guti) context.UePool.Store(ue.Supi, ue) } else { - logger.ContextLog.Infof("Ue with Guti not found locally and in DB: ", guti) + logger.ContextLog.Infoln("Ue with Guti not found locally and in DB: ", guti) } } else { - logger.ContextLog.Infof("Ue with Guti not found : ", guti) + logger.ContextLog.Infoln("Ue with Guti not found : ", guti) } return } diff --git a/context/db.go b/context/db.go index 798d94fe..f84327df 100644 --- a/context/db.go +++ b/context/db.go @@ -185,7 +185,7 @@ func DbFetchRanUeByRanUeNgapID(ranUeNgapID int64, ran *AmfRan) *RanUe { ue := DbFetch(AmfUeDataColl, filter) if ue == nil { - logger.ContextLog.Errorf("DbFetchRanUeByRanUeNgapID: no document found for ranUeNgapID ", ranUeNgapID) + logger.ContextLog.Errorln("DbFetchRanUeByRanUeNgapID: no document found for ranUeNgapID ", ranUeNgapID) return nil } @@ -207,7 +207,7 @@ func DbFetchRanUeByAmfUeNgapID(amfUeNgapID int64) *RanUe { filter["customFieldsAmfUe.amfUeNgapId"] = amfUeNgapID ue := DbFetch(AmfUeDataColl, filter) if ue == nil { - logger.ContextLog.Errorf("DbFetchRanUeByAmfUeNgapID : no document found for amfUeNgapID ", amfUeNgapID) + logger.ContextLog.Errorln("DbFetchRanUeByAmfUeNgapID : no document found for amfUeNgapID ", amfUeNgapID) return nil } @@ -230,7 +230,7 @@ func DbFetchUeByGuti(guti string) (ue *AmfUe, ok bool) { ue = DbFetch(AmfUeDataColl, filter) if ue == nil { - logger.ContextLog.Warnf("FindByGuti : no document found for guti ", guti) + logger.ContextLog.Warnln("FindByGuti : no document found for guti ", guti) return nil, false } else { ok = true @@ -240,7 +240,7 @@ func DbFetchUeByGuti(guti string) (ue *AmfUe, ok bool) { //fetched AmfUe. If so, then return the same. //else return newly fetched AmfUe and store in context if amfUe, ret := self.AmfUeFindByGutiLocal(guti); ret { - logger.ContextLog.Infof("FindByGuti : found by local", guti) + logger.ContextLog.Infoln("FindByGuti : found by local", guti) ue = amfUe ok = ret } @@ -255,7 +255,7 @@ func DbFetchUeBySupi(supi string) (ue *AmfUe, ok bool) { ue = DbFetch(AmfUeDataColl, filter) if ue == nil { - logger.ContextLog.Warnf("FindBySupi : no document found for supi ", supi) + logger.ContextLog.Warnln("FindBySupi : no document found for supi ", supi) return nil, false } else { ok = true @@ -264,7 +264,7 @@ func DbFetchUeBySupi(supi string) (ue *AmfUe, ok bool) { //fetched AmfUe. If so, then return the same. //else return newly fetched AmfUe and store in context if amfUe, ret := self.AmfUeFindBySupiLocal(supi); ret { - logger.ContextLog.Infof("FindBySupi : found by local", supi) + logger.ContextLog.Infoln("FindBySupi : found by local", supi) ue = amfUe ok = ret } diff --git a/gmm/handler.go b/gmm/handler.go index d2c64472..37b2814e 100644 --- a/gmm/handler.go +++ b/gmm/handler.go @@ -250,8 +250,8 @@ func transport5GSMMessage(ue *context.AmfUe, anType models.AccessType, newSmContext.SetUserLocation(deepcopy.Copy(ue.Location).(models.UserLocation)) ue.StoreSmContext(pduSessionID, newSmContext) ue.GmmLog.Infof("create smContext[pduSessionID: %d] Success", pduSessionID) - ue.PublishUeCtxtInfo() // TODO: handle response(response N2SmInfo to RAN if exists) + ue.PublishUeCtxtInfo() } } case nasMessage.ULNASTransportRequestTypeModificationRequest: @@ -1614,7 +1614,7 @@ func NetworkInitiatedDeregistrationProcedure(ue *context.AmfUe, accessType model return err } -//TODO: to be implemented +// TODO: to be implemented func HandleUeSliceInfoDelete(ue *context.AmfUe, accessType models.AccessType, nssai models.Snssai) (err error) { //TODO send configuration update to update allowed nssai list with re-registration required to UE @@ -1652,7 +1652,7 @@ func HandleUeSliceInfoDelete(ue *context.AmfUe, accessType models.AccessType, ns return err } -//TODO: to be implemented +// TODO: to be implemented func HandleUeSliceInfoAdd(ue *context.AmfUe, accessType models.AccessType, nssai models.Snssai) (err error) { //TODO send configuration update to update allowed nssai list with re-registration required to UE diff --git a/gmm/sm.go b/gmm/sm.go index 97e9a71d..a923e7a4 100644 --- a/gmm/sm.go +++ b/gmm/sm.go @@ -157,6 +157,7 @@ func Authentication(state *fsm.State, event fsm.EventType, args fsm.ArgsType) { amfUe.GmmLog = amfUe.GmmLog.WithField(logger.FieldSuci, fmt.Sprintf("SUCI:%s", amfUe.Suci)) amfUe.TxLog = amfUe.TxLog.WithField(logger.FieldSuci, fmt.Sprintf("SUCI:%s", amfUe.Suci)) amfUe.GmmLog.Debugln("EntryEvent at GMM State[Authentication]") + amfUe.PublishUeCtxtInfo() fallthrough case AuthRestartEvent: amfUe = args[ArgAmfUe].(*context.AmfUe) diff --git a/metrics/kafka.go b/metrics/kafka.go index f90f7a32..a3edc9ab 100644 --- a/metrics/kafka.go +++ b/metrics/kafka.go @@ -95,7 +95,8 @@ func PublishMsgEvent(msgType mi.AmfMsgType) error { StatWriter.SendMessage(msg) } return nil -}*/ +} +*/ func (writer Writer) PublishNfStatusEvent(msgEvent mi.MetricEvent) error { diff --git a/metrics/telemetry.go b/metrics/telemetry.go index 653e5825..8789117a 100644 --- a/metrics/telemetry.go +++ b/metrics/telemetry.go @@ -19,7 +19,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" ) -//AmfStats captures AMF level stats +// AmfStats captures AMF level stats type AmfStats struct { ngapMsg *prometheus.CounterVec gnbSessionProfile *prometheus.GaugeVec @@ -61,18 +61,18 @@ func init() { } } -//InitMetrics initialises AMF stats +// InitMetrics initialises AMF stats func InitMetrics() { http.Handle("/metrics", promhttp.Handler()) http.ListenAndServe(":9089", nil) } -//IncrementNgapMsgStats increments message level stats +// IncrementNgapMsgStats increments message level stats func IncrementNgapMsgStats(amfID, msgType, direction, result, reason string) { amfStats.ngapMsg.WithLabelValues(amfID, msgType, direction, result, reason).Inc() } -//SetGnbSessProfileStats maintains Session profile info +// SetGnbSessProfileStats maintains Session profile info func SetGnbSessProfileStats(id, ip, state, tac string, count uint64) { amfStats.gnbSessionProfile.WithLabelValues(id, ip, state, tac).Set(float64(count)) } diff --git a/ngap/ngap_test.go b/ngap/ngap_test.go index 2017f192..ee7940f1 100644 --- a/ngap/ngap_test.go +++ b/ngap/ngap_test.go @@ -1,8 +1,6 @@ // SPDX-FileCopyrightText: 2021 Open Networking Foundation // // SPDX-License-Identifier: Apache-2.0 -// - package ngap_test import ( diff --git a/producer/oam_test.go b/producer/oam_test.go index cf6d9af1..f1d1bd03 100644 --- a/producer/oam_test.go +++ b/producer/oam_test.go @@ -35,6 +35,7 @@ func init() { func TestHandleOAMPurgeUEContextRequest_UEDeregistered(t *testing.T) { self := context.AMF_Self() + self.Drsm, _ = util.MockDrsmInit() amfUe := self.NewAmfUe("imsi-208930100007497") HandleOAMPurgeUEContextRequest(amfUe.Supi, "", nil) diff --git a/service/init.go b/service/init.go index 118ae91d..af82f4f0 100644 --- a/service/init.go +++ b/service/init.go @@ -503,7 +503,7 @@ func (amf *AMF) BuildAndSendRegisterNFInstance() (models.NfProfile, error) { self := context.AMF_Self() profile, err := consumer.BuildNFInstance(self) if err != nil { - initLog.Error("Build AMF Profile Error: %v", err) + initLog.Errorf("Build AMF Profile Error: %v", err) return profile, err } initLog.Infof("Pcf Profile Registering to NRF: %v", profile) @@ -512,7 +512,7 @@ func (amf *AMF) BuildAndSendRegisterNFInstance() (models.NfProfile, error) { return profile, err } -//UpdateNF is the callback function, this is called when keepalivetimer elapsed +// UpdateNF is the callback function, this is called when keepalivetimer elapsed func (amf *AMF) UpdateNF() { KeepAliveTimerMutex.Lock() defer KeepAliveTimerMutex.Unlock() @@ -630,6 +630,9 @@ func (amf *AMF) UpdateConfig(commChannel chan *protos.NetworkSliceResponse) bool logger.GrpcLog.Infof("Received updateConfig in the amf app : %v", rsp) var tai []models.Tai var plmnList []*factory.PlmnSupportItem + if rsp.NetworkSlice == nil { + return false + } for _, ns := range rsp.NetworkSlice { var snssai *models.Snssai logger.GrpcLog.Infoln("Network Slice Name ", ns.Name) @@ -692,6 +695,7 @@ func (amf *AMF) UpdateConfig(commChannel chan *protos.NetworkSliceResponse) bool } func (amf *AMF) SendNFProfileUpdateToNrf() { + //for rocUpdateConfig := range RocUpdateConfigChannel { for rocUpdateConfig := range RocUpdateConfigChannel { if rocUpdateConfig { self := context.AMF_Self() diff --git a/util/init_context.go b/util/init_context.go index 73a91137..f9b92f49 100644 --- a/util/init_context.go +++ b/util/init_context.go @@ -28,7 +28,7 @@ func InitDrsm() (drsm.DrsmInterface, error) { podId := drsm.PodId{PodName: podname, PodInstance: context.AMF_Self().NfId, PodIp: podip} logger.UtilLog.Debugf("PodId: %v", podId) dbUrl := "mongodb://mongodb-arbiter-headless" - if factory.AmfConfig.Configuration.Mongodb != nil || + if factory.AmfConfig.Configuration.Mongodb != nil && factory.AmfConfig.Configuration.Mongodb.Url != "" { dbUrl = factory.AmfConfig.Configuration.Mongodb.Url } diff --git a/util/mock.drsm.go b/util/mock.drsm.go new file mode 100644 index 00000000..9ac3d0c8 --- /dev/null +++ b/util/mock.drsm.go @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: 2022 Open Networking Foundation +// +// SPDX-License-Identifier: Apache-2.0 +// + +package util + +import ( + "github.com/omec-project/amf/logger" + "github.com/omec-project/util/drsm" +) + +type MockDrsmInterface interface { + AllocateInt32ID() (int32, error) + ReleaseInt32ID(id int32) error + FindOwnerInt32ID(id int32) (*drsm.PodId, error) + AcquireIp(pool string) (string, error) + ReleaseIp(pool, ip string) error + CreateIpPool(poolName string, ipPool string) error + DeleteIpPool(poolName string) error + DeletePod(string) +} +type MockDrsm struct { +} + +func MockDrsmInit() (drsm.DrsmInterface, error) { + //db := drsm.DbInfo{"mongodb://mongodb", "amf"} + //podId := drsm.PodId{"amf-instance1", "1.1.1.1"} + //opt := &drsm.Options{ResIdSize: 24, Mode: drsm.ResourceClient} + d := &MockDrsm{} + return d, nil +} + +func (d *MockDrsm) DeletePod(s string) { + logger.AppLog.Info("MockDeletePod") +} + +func (d *MockDrsm) AllocateInt32ID() (int32, error) { + logger.AppLog.Info("MockAllocate") + return 1, nil +} + +func (d *MockDrsm) ReleaseInt32ID(id int32) error { + logger.AppLog.Info("MockRelease") + return nil +} + +func (d *MockDrsm) FindOwnerInt32ID(id int32) (*drsm.PodId, error) { + return nil, nil +} + +func (d *MockDrsm) AcquireIp(pool string) (string, error) { + return "", nil +} + +func (d *MockDrsm) ReleaseIp(pool, ip string) error { + return nil +} + +func (d *MockDrsm) CreateIpPool(poolName string, ipPool string) error { + return nil +} + +func (d *MockDrsm) DeleteIpPool(poolName string) error { + return nil +}