Skip to content

Commit

Permalink
GitHub actions (#92)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
vthiruveedula and UpadhyayaAnkur authored Jan 25, 2023
1 parent a4759db commit 3b7558f
Show file tree
Hide file tree
Showing 22 changed files with 332 additions and 52 deletions.
22 changes: 22 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"

43 changes: 43 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
# 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
21 changes: 21 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
version: latest
args: -v --config ./.golangci.yml
48 changes: 48 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: |
Updated with changes from CI
branch: ${{ github.event.pull_request.head.ref }}
author: "Github Actions <actions@github>"
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
18 changes: 18 additions & 0 deletions .github/workflows/reuse.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions .github/workflows/run-amf-unit-test.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"

Expand All @@ -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"
Expand Down
39 changes: 35 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
36 changes: 20 additions & 16 deletions amf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0
//

/*
* AMF Unit Testcases
*
Expand All @@ -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")
}

Expand All @@ -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

Expand All @@ -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 {
Expand Down Expand Up @@ -102,7 +105,7 @@ func TestUpdateConfig(t *testing.T) {
Rsp <- &nrp
}()
go func() {
AMF.UpdateConfig(Rsp)
AMFTest.UpdateConfig(Rsp)
}()

time.Sleep(2 * time.Second)
Expand All @@ -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")
Expand All @@ -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)
*/
}
6 changes: 3 additions & 3 deletions context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 3b7558f

Please sign in to comment.