Skip to content

Commit b612c04

Browse files
committed
WIP
1 parent 9b97e2c commit b612c04

File tree

8 files changed

+94
-37
lines changed

8 files changed

+94
-37
lines changed

Makefile

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ DEFAULT_DOCKER_VERSION := 1.12.6
99
V2PLUGIN_DOCKER_VERSION := 1.13.1
1010
SHELL := /bin/bash
1111
# TODO: contivmodel should be removed once its code passes golint and misspell
12-
EXCLUDE_DIRS := bin docs Godeps scripts vagrant vendor install contivmodel
12+
EXCLUDE_DIRS := bin docs Godeps scripts vagrant vendor install contivmodel venv
1313
PKG_DIRS := $(filter-out $(EXCLUDE_DIRS),$(subst /,,$(sort $(dir $(wildcard */)))))
1414
TO_BUILD := ./netplugin/ ./netmaster/ ./netctl/netctl/ ./mgmtfn/k8splugin/contivk8s/ ./mgmtfn/mesosplugin/netcontiv/
1515
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
@@ -131,9 +131,18 @@ update:
131131
start:
132132
CONTIV_DOCKER_VERSION="$${CONTIV_DOCKER_VERSION:-$(DEFAULT_DOCKER_VERSION)}" CONTIV_NODE_OS=${CONTIV_NODE_OS} vagrant up
133133

134+
# ===================================================================
135+
# kubernetes helper targets
136+
137+
k8s-check-python-deps:
138+
@command -v pip >/dev/null \
139+
|| echo No pip available, make sure netaddr and parse packages are installed
140+
@command -v pip >/dev/null && pip show -q netaddr && pip show -q parse \
141+
|| (echo parse and netaddr python packages are required; exit 1)
142+
134143
# ===================================================================
135144
# kubernetes cluster bringup/cleanup targets
136-
k8s-cluster:
145+
k8s-cluster: k8s-check-python-deps
137146
cd vagrant/k8s/ && CONTIV_K8S_USE_KUBEADM=1 ./setup_cluster.sh
138147

139148
k8s-l3-cluster:
@@ -147,11 +156,24 @@ k8s-l3-destroy:
147156

148157
# ===================================================================
149158
# kubernetes test targets
150-
k8s-test: k8s-cluster
151-
cd vagrant/k8s/ && vagrant ssh k8master -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"'
152-
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py -scheduler 'k8s' -binpath contiv/bin -install_mode 'kubeadm'
153-
CONTIV_K8S_USE_KUBEADM=1 CONTIV_NODES=3 go test -v -timeout 540m ./test/systemtests -check.v -check.abort -check.f $(K8S_SYSTEM_TESTS_TO_RUN)
154-
cd vagrant/k8s && vagrant destroy -f
159+
k8s-build: FIRST_MASTER_HOSTNAME:=k8master
160+
k8s-build: first_master_make_targets:="compile archive"
161+
k8s-build: export VAGRANT_CWD=$(PWD)/vagrant/k8s
162+
k8s-build: TO_BUILD := netplugin netmaster mgmtfn test/systemtests
163+
k8s-build: make-on-first-master-dep
164+
165+
# for k8s-test, run-build will be run on the node instead of local
166+
k8s-test: FIRST_MASTER_HOSTNAME:=k8master
167+
k8s-test: first_master_make_targets:=run-build
168+
k8s-test: export VAGRANT_CWD:=$(PWD)/vagrant/k8s
169+
k8s-test: export CONTIV_K8S_USE_KUBEADM:=1 CONTIV_NODES:=3 PYTHONIOENCODING:=utf-8
170+
k8s-test: k8s-cluster make-on-first-master-dep
171+
k8s-test-now:
172+
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python \
173+
&& ./createcfg.py -scheduler 'k8s' -binpath contiv/bin -install_mode 'kubeadm'
174+
go test -v -timeout 540m ./test/systemtests -check.v -check.abort -check.f \
175+
$(K8S_SYSTEM_TESTS_TO_RUN)
176+
#cd vagrant/k8s && vagrant destroy -f
155177

156178
k8s-l3-test: k8s-l3-cluster
157179
cd vagrant/k8s/ && vagrant ssh k8master -c 'bash -lc "cd /opt/gopath/src/github.com/contiv/netplugin && make run-build"'
@@ -204,7 +226,7 @@ integ-test: stop clean start ssh-build
204226
ubuntu-tests:
205227
CONTIV_NODE_OS=ubuntu make clean build unit-test system-test stop
206228

207-
system-test:start
229+
system-test: start
208230
@echo "system-test: running the following system tests:" $(SYSTEM_TESTS_TO_RUN)
209231
cd $(GOPATH)/src/github.com/contiv/netplugin/scripts/python && PYTHONIOENCODING=utf-8 ./createcfg.py
210232
go test -v -timeout 480m ./test/systemtests -check.v -check.abort -check.f $(SYSTEM_TESTS_TO_RUN)
@@ -293,7 +315,7 @@ host-plugin-create:
293315
host-plugin-update: host-plugin-remove unarchive host-plugin-create
294316
# same behavior as host-plugin-update but runs locally with docker 1.13+
295317
plugin-update: tar
296-
$(call make-on-node1, host-plugin-update)
318+
$(call make-on-first-master, host-plugin-update)
297319

298320
# cleanup all containers, recreate and start the v2plugin on all hosts
299321
# uses the latest compiled binaries
@@ -315,21 +337,23 @@ host-pluginfs-unpack:
315337
--exclude=etc/terminfo/v/vt220
316338

317339
# Runs make targets on the first netplugin vagrant node
318-
# this is used as a macro like $(call make-on-node1, compile checks)
319-
make-on-node1 = vagrant ssh netplugin-node1 -c '\
340+
# this is used as a macro like $(call make-on-first-master, compile checks)
341+
342+
FIRST_MASTER_HOSTNAME ?= netplugin-node1
343+
make-on-first-master = vagrant ssh $(FIRST_MASTER_HOSTNAME) -c '\
320344
bash -lc "source /etc/profile.d/envvar.sh \
321345
&& cd /opt/gopath/src/github.com/contiv/netplugin && make $(1)"'
322346

323-
# Calls macro make-on-node1 but can be used as a dependecy by setting
324-
# the variable "node1-make-targets"
325-
make-on-node1-dep:
326-
$(call make-on-node1, $(node1-make-targets))
347+
# Calls macro make-on-first-master but can be used as a dependecy by setting
348+
# the variable "first_master_make_targets"
349+
make-on-first-master-dep:
350+
$(call make-on-first-master, $(first_master_make_targets))
327351

328352
# assumes the v2plugin archive is available, installs the v2plugin and resets
329353
# everything on the vm to clean state
330354
v2plugin-install:
331355
@echo Installing v2plugin
332-
$(call make-on-node1, install-shell-completion host-pluginfs-unpack \
356+
$(call make-on-first-master, install-shell-completion host-pluginfs-unpack \
333357
host-plugin-restart host-swarm-restart)
334358

335359
# Just like demo-v2plugin except builds are done locally and cached
@@ -341,8 +365,8 @@ demo-v2plugin-from-local: tar host-pluginfs-create start v2plugin-install
341365
# then creates and enables v2plugin
342366
demo-v2plugin: export CONTIV_DOCKER_VERSION ?= $(V2PLUGIN_DOCKER_VERSION)
343367
demo-v2plugin: export CONTIV_DOCKER_SWARM := swarm_mode
344-
demo-v2plugin: node1-make-targets := host-pluginfs-create
345-
demo-v2plugin: ssh-build make-on-node1-dep v2plugin-install
368+
demo-v2plugin: first_master_make_targets := host-pluginfs-create
369+
demo-v2plugin: ssh-build make-on-first-master-dep v2plugin-install
346370

347371
# release a v2 plugin from the VM
348372
host-plugin-release: tar host-pluginfs-create host-pluginfs-unpack host-plugin-create

mgmtfn/k8splugin/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ func addPod(w http.ResponseWriter, r *http.Request, vars map[string]string) (int
404404
ep, err := createEP(epReq)
405405
if err != nil {
406406
log.Errorf("Error creating ep. Err: %v", err)
407-
setErrorResp(&resp, "Error creating EP", err)
407+
setErrorResp(&resp, "Error creating EP '"+epReq.Name+"'", err)
408408
return resp, err
409409
}
410410

scripts/netContain/scripts/contivNet.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ if [ $netmaster == true ]; then
131131
sleep 5
132132
done
133133
elif [ $netplugin == true ]; then
134-
echo "Starting netplugin"
135134
if [[ "$cluster_store" =~ ^etcd://.+ ]]; then
136135
store_arg="--etcd-endpoints $(echo $cluster_store | sed s/etcd/http/)"
137136
elif [[ "$cluster_store" =~ ^consul://.+ ]]; then
@@ -146,7 +145,10 @@ elif [ $netplugin == true ]; then
146145
if [ "$vlan_if" != "" ]; then
147146
vlan_if_param="--vlan-if"
148147
fi
148+
echo "Starting netplugin $(date)"
149+
set -x
149150
/contiv/bin/netplugin $debug $store_arg $vtep_ip_param $vtep_ip $vlan_if_param $vlan_if --plugin-mode $plugin || true
151+
set +x
150152
echo "CRITICAL : Netplugin has exited. Trying to respawn in 5s"
151153
fi
152154
sleep 5

state/etcdstatedriver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func (d *EtcdStateDriver) Read(key string) ([]byte, error) {
127127
}
128128

129129
if client.IsKeyNotFound(err) {
130-
return []byte{}, core.Errorf("key not found")
130+
return []byte{}, core.Errorf("key '%s' not found", key)
131131
}
132132

133133
if err.Error() == client.ErrClusterUnavailable.Error() {

test/systemtests/How-to-Run.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# A guide to running netplugin systemtests on Vagrant and Baremetal platforms:
2+
13
Current framework can run system-tests for
24

35
```
@@ -9,7 +11,6 @@ Baremetal-
911
Swarm -- ACI
1012
Swarm -- Non-ACI
1113
```
12-
A guide to running netplugin systemtests on Vagrant and Baremetal platforms:
1314

1415
Customize the example JSON file `netplugin/systemtests/cfg.json.example` according to your environment and rename it to `netplugin/systemtests/cfg.json`. A typical file for vagrant with swarm looks like:
1516
```
@@ -46,15 +47,33 @@ Customize the example JSON file `netplugin/systemtests/cfg.json.example` accordi
4647
]
4748
```
4849

49-
Testing with Vagrant:
50+
51+
### Testing with Vagrant:
5052

5153
* Make a suitable JSON file on your local machine (inside the systemtests directory).
5254
* From the netplugin directory of your machine (outside the vagrant nodes), run:
5355

5456
```
5557
make system-test
5658
```
57-
Testing with Baremetal with Swarm:
59+
60+
61+
### Testing k8s with Vagrant:
62+
63+
To run all the k8s system tests:
64+
65+
```
66+
make k8s-test
67+
```
68+
69+
To work on a single system test, such as TestNetworkAddDeleteNoGatewayVLAN:
70+
71+
```
72+
make K8S_SYSTEM_TESTS_TO_RUN=TestNetworkAddDeleteNoGatewayVLAN start k8s-test
73+
```
74+
75+
76+
### Testing with Baremetal with Swarm:
5877

5978
For ACI testing , We need to have connectivity to APIC and ACI Fabric Switches from Baremetal VMs and Hosts.
6079
* You need to complete Pre-requisites, Step 1, Step 2, Step3 metioned here : https://github.com/contiv/demo/tree/master/net
@@ -84,7 +103,9 @@ godep go test -v -timeout 240m ./systemtests -check.v -check.f "TestACI"
84103
85104
This will run all the test functions which have the string TestACI
86105
```
87-
Troubleshooting
106+
107+
108+
### Troubleshooting
88109

89110
* First delete all netmaster, netctl, netplugin, contivk8s binaries from $GOBIN directory from all Nodes in the Cluster
90111
* You can perform following steps to clear etcd states

test/systemtests/kubeadm_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
"strconv"
1010
"strings"
1111

12-
"github.com/Sirupsen/logrus"
1312
"os"
1413
"time"
14+
15+
"github.com/Sirupsen/logrus"
1516
)
1617

1718
type kubePod struct {
@@ -618,7 +619,9 @@ func (k *kubePod) runCommandUntilNoNetmasterError() error {
618619
}
619620

620621
processCheckCmd := `kubectl -n kube-system exec ` + podName + ` -- pgrep netmaster`
621-
return k8sMaster.runCommandUntilNoError(processCheckCmd)
622+
err = k8sMaster.runCommandUntilNoError(processCheckCmd)
623+
logrus.Infof("netmaster status check complete on: %s", k.node.Name())
624+
return err
622625
}
623626

624627
func (k *kubePod) runCommandUntilNoNetpluginError() error {
@@ -633,7 +636,8 @@ func (k *kubePod) runCommandUntilNoNetpluginError() error {
633636
}
634637

635638
processCheckCmd := `kubectl -n kube-system exec ` + podName + ` -- pgrep netplugin`
636-
return k8sMaster.runCommandUntilNoError(processCheckCmd)
639+
err = k8sMaster.runCommandUntilNoError(processCheckCmd)
640+
return err
637641
}
638642

639643
func (k *kubePod) rotateNetmasterLog() error {

test/systemtests/network_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,13 @@ func (s *systemtestSuite) testNetworkAddDeleteNoGateway(c *C, encap string) {
259259

260260
for _, name := range netNames {
261261
var err error
262-
// There seem to be a docker bug in creating external connectivity if we run
263-
// containers in parallel. So, running it serially for this test
264-
containers[name], err = s.runContainersSerial(numContainer, false, name, "", nil)
262+
if s.basicInfo.Scheduler == "k8s" {
263+
containers[name], err = s.runContainers(numContainer, false, name, "", nil, nil)
264+
} else {
265+
// There seem to be a docker bug in creating external connectivity if we run
266+
// containers in parallel. So, running it serially for this test
267+
containers[name], err = s.runContainersSerial(numContainer, false, name, "", nil)
268+
}
265269
c.Assert(err, IsNil)
266270
}
267271

test/systemtests/util_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (s *systemtestSuite) runContainers(num int, withService bool, networkName s
186186
for i := 0; i < num; i++ {
187187
go func(i int) {
188188
nodeNum := i % len(s.nodes)
189-
var name string
189+
var name, cname string
190190

191191
mutex.Lock()
192192
if len(names) > 0 {
@@ -197,6 +197,9 @@ func (s *systemtestSuite) runContainers(num int, withService bool, networkName s
197197

198198
if name == "" {
199199
name = fmt.Sprintf("%s-srv%d-%d", strings.Replace(networkName, "/", "-", -1), i, nodeNum)
200+
cname = name
201+
} else {
202+
cname = fmt.Sprintf("%s-%d", name, i)
200203
}
201204

202205
var serviceName string
@@ -205,7 +208,6 @@ func (s *systemtestSuite) runContainers(num int, withService bool, networkName s
205208
serviceName = name
206209
}
207210

208-
cname := fmt.Sprintf("%s-%d", name, i)
209211
spec := containerSpec{
210212
imageName: "contiv/alpine",
211213
networkName: networkName,
@@ -1249,8 +1251,8 @@ func (s *systemtestSuite) SetUpSuiteVagrant(c *C) {
12491251
c.Assert(s.vagrant.Setup(false, []string{"CONTIV_L3=1 VAGRANT_CWD=" + topDir + "/src/github.com/contiv/netplugin/vagrant/k8s/"}, contivNodes), IsNil)
12501252

12511253
// Sleep to give enough time for the netplugin pods to come up
1252-
logrus.Infof("Sleeping for 1 minute for pods to come up")
1253-
time.Sleep(time.Minute)
1254+
//logrus.Infof("Sleeping for 1 minute for pods to come up")
1255+
// time.Sleep(time.Minute)
12541256

12551257
case swarmScheduler:
12561258
c.Assert(s.vagrant.Setup(false, append([]string{"CONTIV_NODES=3 CONTIV_L3=1"}, s.basicInfo.SwarmEnv), contivNodes+contivL3Nodes), IsNil)
@@ -1276,8 +1278,8 @@ func (s *systemtestSuite) SetUpSuiteVagrant(c *C) {
12761278
c.Assert(s.vagrant.Setup(false, []string{"VAGRANT_CWD=" + topDir + "/src/github.com/contiv/netplugin/vagrant/k8s/"}, contivNodes), IsNil)
12771279

12781280
// Sleep to give enough time for the netplugin pods to come up
1279-
logrus.Infof("Sleeping for 1 minute for pods to come up")
1280-
time.Sleep(time.Minute)
1281+
//logrus.Infof("Sleeping for 1 minute for pods to come up")
1282+
//time.Sleep(time.Minute)
12811283

12821284
case swarmScheduler:
12831285
c.Assert(s.vagrant.Setup(false, append([]string{}, s.basicInfo.SwarmEnv), contivNodes), IsNil)

0 commit comments

Comments
 (0)