Skip to content

Commit c44e775

Browse files
authored
NPM test fixes + Azure Pipelines (#402)
Initial Azure Pipelines config, run pipeline tests in container, CNM and NPM fixes
1 parent 3ad4968 commit c44e775

File tree

13 files changed

+221
-22
lines changed

13 files changed

+221
-22
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ ipam-*.xml
88

99
# Environment
1010
.vscode/*
11+
12+
# Coverage
13+
*.out

.pipelines/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM ubuntu:16.04
2+
RUN apt-get update && apt-get install -y software-properties-common sudo wget apt-transport-https curl
3+
RUN wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
4+
RUN sudo dpkg -i packages-microsoft-prod.deb
5+
RUN add-apt-repository ppa:longsleep/golang-backports && apt-get update
6+
RUN apt-get install -y git golang-go=2:1.13~1longsleep1+xenial iptables ipset iproute2 ebtables python-pip gcc zip dotnet-sdk-2.2
7+
RUN sudo pip install coverage
8+
RUN if [ -f Gopkg.toml ]; then curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh ; fi
9+
RUN go get github.com/docker/libnetwork/driverapi
10+
RUN go get github.com/gorilla/mux
11+
RUN go get github.com/jstemmer/go-junit-report
12+
RUN go get github.com/axw/gocov/gocov
13+
RUN go get github.com/AlekSi/gocov-xml
14+
RUN go get -u gopkg.in/matm/v1/gocov-html
15+
ENV PATH="/root/go/bin:${PATH}"
16+

.pipelines/pipeline.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
pr:
2+
- master
3+
4+
trigger:
5+
branches:
6+
include:
7+
- master
8+
9+
jobs:
10+
- job: UnitTest
11+
pool:
12+
name: Networking-ContainerNetworking
13+
demands: agent.os -equals Linux
14+
15+
container:
16+
image: containernetworking/pipeline-ci:1.0.3
17+
options: "--privileged"
18+
19+
# Go setup for the vmImage:
20+
# https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/linux/scripts/installers/go.sh
21+
variables:
22+
GOBIN: "$(GOPATH)/bin" # Go binaries path
23+
GOPATH: "$(System.DefaultWorkingDirectory)/gopath" # Go workspace path
24+
modulePath: "$(GOPATH)/src/github.com/Azure/azure-container-networking" # $(build.repository.name)' # Path to the module's code
25+
26+
steps:
27+
- bash: |
28+
echo $UID
29+
sudo apt-get install -y ebtables ipset python3-dev gcc zip iptables ipset
30+
sudo pip install coverage
31+
displayName: "Install OS dependencies"
32+
33+
- bash: |
34+
go version
35+
go env
36+
mkdir -p '$(GOBIN)'
37+
mkdir -p '$(GOPATH)/pkg'
38+
mkdir -p '$(modulePath)'
39+
shopt -s extglob
40+
shopt -s dotglob
41+
mv !(gopath) '$(modulePath)'
42+
echo '##vso[task.prependpath]$(GOBIN)'
43+
echo '##vso[task.prependpath]$(GOROOT)/bin'
44+
displayName: "Set up the Go workspace"
45+
46+
- bash: |
47+
go get -v -t -d ./...
48+
if [ -f Gopkg.toml ]; then
49+
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
50+
fi
51+
go get github.com/docker/libnetwork/driverapi
52+
go get github.com/gorilla/mux
53+
go get github.com/jstemmer/go-junit-report
54+
go get github.com/axw/gocov/gocov
55+
go get github.com/AlekSi/gocov-xml
56+
go get -u gopkg.in/matm/v1/gocov-html
57+
workingDirectory: "$(modulePath)"
58+
displayName: "Install Go dependencies"
59+
60+
- bash: |
61+
sudo rm /run/docker/plugins/test.sock || true
62+
sudo ip link del dev dummy || true
63+
workingDirectory: "$(modulePath)"
64+
displayName: "Workspace setup"
65+
condition: always()
66+
67+
- bash: |
68+
export GOOS=linux
69+
make all-binaries
70+
export GOOS=windows
71+
make all-binaries
72+
cd output
73+
sudo find . -mindepth 2 -type f -regextype posix-extended ! -iregex '.*\.(zip|tgz)$' -delete
74+
sudo find . -mindepth 2 -type f -print -exec mv {} . \;
75+
sudo rm -R -- */
76+
workingDirectory: "$(modulePath)"
77+
displayName: "Build"
78+
79+
- bash: |
80+
# run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout
81+
{ { { {
82+
sudo -E env "PATH=$PATH" make test-all;
83+
echo $? >&3;
84+
} | tee >(go-junit-report > report.xml) >&4;
85+
} 3>&1;
86+
} | { read xs; exit $xs; }
87+
} 4>&1
88+
workingDirectory: "$(modulePath)"
89+
failOnStderr: true
90+
displayName: "Run Tests"
91+
92+
- bash: |
93+
bash <(curl -s https://codecov.io/bash)
94+
gocov convert coverage.out > coverage.json
95+
gocov-xml < coverage.json > coverage.xml
96+
workingDirectory: "$(modulePath)"
97+
displayName: "Generate Coverage Reports"
98+
condition: always()
99+
100+
- task: PublishTestResults@2
101+
inputs:
102+
testRunner: JUnit
103+
testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml
104+
condition: always()
105+
106+
- task: PublishCodeCoverageResults@1
107+
inputs:
108+
codeCoverageTool: Cobertura
109+
summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
110+
condition: always()
111+
112+
- task: CopyFiles@2
113+
inputs:
114+
sourceFolder: "$(modulePath)/output"
115+
targetFolder: $(Build.ArtifactStagingDirectory)
116+
condition: succeeded()
117+
118+
- task: PublishBuildArtifacts@1
119+
inputs:
120+
artifactName: "output"
121+
pathtoPublish: "$(Build.ArtifactStagingDirectory)"
122+
condition: succeeded()

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,20 @@ ifeq ($(GOOS),linux)
301301
cp telemetry/azure-vnet-telemetry.config $(NPM_BUILD_DIR)/azure-vnet-telemetry.config
302302
cd $(NPM_BUILD_DIR) && $(ARCHIVE_CMD) $(NPM_ARCHIVE_NAME) azure-npm$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) azure-vnet-telemetry.config
303303
chown $(BUILD_USER):$(BUILD_USER) $(NPM_BUILD_DIR)/$(NPM_ARCHIVE_NAME)
304-
endif
304+
endif
305+
306+
# run all tests
307+
.PHONY: test-all
308+
test-all:
309+
go test -v -covermode count -coverprofile=coverage.out \
310+
./ipam/ \
311+
./log/ \
312+
./netlink/ \
313+
./store/ \
314+
./telemetry/ \
315+
./cnm/network/ \
316+
./cni/ipam/ \
317+
./cns/ipamclient/ \
318+
./npm/iptm/ \
319+
./npm/ipsm/ \
320+
./npm

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Microsoft Azure Container Networking
22

3-
[![CircleCI](https://circleci.com/gh/Azure/azure-container-networking/tree/master.svg?style=svg)](https://circleci.com/gh/Azure/azure-container-networking/tree/master) [![Go Report Card](https://goreportcard.com/badge/github.com/Azure/azure-container-networking)](https://goreportcard.com/report/github.com/Azure/azure-container-networking) ![GitHub release](https://img.shields.io/github/release/Azure/azure-container-networking.svg)
3+
[![Build Status](https://msazure.visualstudio.com/One/_apis/build/status/Custom/Networking/ContainerNetworking/Azure.azure-container-networking?branchName=master)](https://msazure.visualstudio.com/One/_build/latest?definitionId=95007&branchName=master) [![Go Report Card](https://goreportcard.com/badge/github.com/Azure/azure-container-networking)](https://goreportcard.com/report/github.com/Azure/azure-container-networking) ![GitHub release](https://img.shields.io/github/release/Azure/azure-container-networking.svg)
44
[![codecov](https://codecov.io/gh/Azure/azure-container-networking/branch/master/graph/badge.svg)](https://codecov.io/gh/Azure/azure-container-networking)
55

66
## Overview

network/network_linux.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,19 @@ func (nm *networkManager) applyIPConfig(extIf *externalInterface, targetIf *net.
269269
}
270270

271271
func applyDnsConfig(extIf *externalInterface, ifName string) error {
272-
cmd := fmt.Sprintf("systemd-resolve --interface=%s --set-dns=%s", ifName, extIf.DNSInfo.Servers[0])
273-
_, err := platform.ExecuteCommand(cmd)
274-
if err != nil {
275-
return err
272+
var err error
273+
274+
if extIf != nil && len(extIf.DNSInfo.Servers) > 0 {
275+
cmd := fmt.Sprintf("systemd-resolve --interface=%s --set-dns=%s", ifName, extIf.DNSInfo.Servers[0])
276+
_, err = platform.ExecuteCommand(cmd)
277+
if err != nil {
278+
return err
279+
}
280+
281+
cmd = fmt.Sprintf("systemd-resolve --interface=%s --set-domain=%s", ifName, extIf.DNSInfo.Suffix)
282+
_, err = platform.ExecuteCommand(cmd)
276283
}
277284

278-
cmd = fmt.Sprintf("systemd-resolve --interface=%s --set-domain=%s", ifName, extIf.DNSInfo.Suffix)
279-
_, err = platform.ExecuteCommand(cmd)
280285
return err
281286
}
282287

npm/ipsm/ipsm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ func (ipsMgr *IpsetManager) Run(entry *ipsEntry) (int, error) {
350350
_, err := exec.Command(cmdName, cmdArgs...).Output()
351351
if msg, failed := err.(*exec.ExitError); failed {
352352
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
353-
if errCode > 1 {
354-
log.Errorf("Error: There was an error running command: %s %s Arguments:%v", err, cmdName, cmdArgs)
353+
if errCode > 0 {
354+
log.Errorf("Error: There was an error running command: [%s %v] Stderr: [%v, %s]", cmdName, strings.Join(cmdArgs, " "), err, strings.TrimSuffix(string(msg.Stderr), "\n"))
355355
}
356356

357357
return errCode, err

npm/ipsm/ipsm_test.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package ipsm
44

55
import (
66
"testing"
7+
"os"
78

89
"github.com/Azure/azure-container-networking/npm/util"
910
)
@@ -76,6 +77,10 @@ func TestAddToList(t *testing.T) {
7677
}
7778
}()
7879

80+
if err := ipsMgr.CreateSet("test-set"); err != nil {
81+
t.Errorf("TestAddToList failed @ ipsMgr.CreateSet")
82+
}
83+
7984
if err := ipsMgr.AddToList("test-list", "test-set"); err != nil {
8085
t.Errorf("TestAddToList failed @ ipsMgr.AddToList")
8186
}
@@ -93,13 +98,21 @@ func TestDeleteFromList(t *testing.T) {
9398
}
9499
}()
95100

101+
if err := ipsMgr.CreateSet("test-set"); err != nil {
102+
t.Errorf("TestDeleteFromList failed @ ipsMgr.CreateSet")
103+
}
104+
96105
if err := ipsMgr.AddToList("test-list", "test-set"); err != nil {
97106
t.Errorf("TestDeleteFromList failed @ ipsMgr.AddToList")
98107
}
99108

100109
if err := ipsMgr.DeleteFromList("test-list", "test-set"); err != nil {
101110
t.Errorf("TestDeleteFromList failed @ ipsMgr.DeleteFromList")
102111
}
112+
113+
if err := ipsMgr.DeleteSet("test-set"); err != nil {
114+
t.Errorf("TestDeleteSet failed @ ipsMgr.DeleteSet")
115+
}
103116
}
104117

105118
func TestCreateSet(t *testing.T) {
@@ -246,7 +259,9 @@ func TestMain(m *testing.M) {
246259
ipsMgr := NewIpsetManager()
247260
ipsMgr.Save(util.IpsetConfigFile)
248261

249-
m.Run()
262+
exitCode := m.Run()
250263

251264
ipsMgr.Restore(util.IpsetConfigFile)
265+
266+
os.Exit(exitCode)
252267
}

npm/iptm/iptm.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package iptm
99
import (
1010
"os"
1111
"os/exec"
12+
"strings"
1213
"syscall"
1314
"time"
1415

@@ -365,8 +366,8 @@ func (iptMgr *IptablesManager) Run(entry *IptEntry) (int, error) {
365366

366367
if msg, failed := err.(*exec.ExitError); failed {
367368
errCode := msg.Sys().(syscall.WaitStatus).ExitStatus()
368-
if errCode > 1 {
369-
log.Errorf("Error: There was an error running command: %s %s Arguments:%v", err, cmdName, cmdArgs)
369+
if errCode > 0 {
370+
log.Errorf("Error: There was an error running command: [%s %v] Stderr: [%v, %s]", cmdName, strings.Join(cmdArgs, " "), err, strings.TrimSuffix(string(msg.Stderr), "\n"))
370371
}
371372

372373
return errCode, err

npm/iptm/iptm_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package iptm
22

33
import (
44
"testing"
5+
"os"
56

67
"github.com/Azure/azure-container-networking/npm/util"
78
)
@@ -204,7 +205,9 @@ func TestMain(m *testing.M) {
204205
iptMgr := NewIptablesManager()
205206
iptMgr.Save(util.IptablesConfigFile)
206207

207-
m.Run()
208+
exitCode := m.Run()
208209

209210
iptMgr.Restore(util.IptablesConfigFile)
211+
212+
os.Exit(exitCode)
210213
}

0 commit comments

Comments
 (0)