Skip to content

Commit 5cfc83b

Browse files
author
Erik Hollensbe
committed
Merge pull request #133 from contiv/new-vms
Makefile, Vagrantfile: refactor of build system
2 parents a336c36 + 499c1bd commit 5cfc83b

File tree

9 files changed

+100
-166
lines changed

9 files changed

+100
-166
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ _testmain.go
2828

2929
# vagrant
3030
.vagrant
31+
32+
bin/*
33+
34+
resolv.conf

Makefile

+41-23
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
# find all verifiable packages.
55
# XXX: explore a better way that doesn't need multiple 'find'
6-
PKGS := `find . -mindepth 1 -maxdepth 1 -type d -name '*' | grep -vE '/\..*$\|Godeps|examples|docs|scripts|mgmtfn|systemtests'`
7-
PKGS += `find . -mindepth 2 -maxdepth 2 -type d -name '*'| grep -vE '/\..*$\|Godeps|examples|docs|scripts'`
6+
PKGS := `find . -mindepth 1 -maxdepth 1 -type d -name '*' | grep -vE '/\..*$\|Godeps|examples|docs|scripts|mgmtfn|systemtests|bin'`
7+
PKGS += `find . -mindepth 2 -maxdepth 2 -type d -name '*'| grep -vE '/\..*$\|Godeps|examples|docs|scripts|bin'`
88
TO_BUILD := ./netplugin/ ./netmaster/ ./netdcli/ ./mgmtfn/k8contivnet/ ./mgmtfn/dockcontivnet/
99
HOST_GOBIN := `if [ -n "$$(go env GOBIN)" ]; then go env GOBIN; else dirname $$(which go); fi`
1010
HOST_GOROOT := `go env GOROOT`
@@ -34,20 +34,35 @@ deps:
3434
checks:
3535
./scripts/checks "$(PKGS)"
3636

37-
build: deps checks
37+
host-build:
38+
sudo /bin/bash -c 'source /etc/profile.d/envvar.sh; make run-build'
39+
40+
run-build: deps checks clean
3841
godep go install -v $(TO_BUILD)
3942

43+
build: start
44+
vagrant ssh netplugin-node1 -c 'sudo -i bash -lc "source /etc/profile.d/envvar.sh && cd /opt/golang/src/github.com/contiv/netplugin && make run-build"'
45+
make stop
46+
4047
clean: deps
4148
rm -rf Godeps/_workspace/pkg
4249
godep go clean -i -v ./...
4350

51+
update:
52+
vagrant box update
53+
4454
# setting CONTIV_NODES=<number> while calling 'make demo' can be used to bring
4555
# up a cluster of <number> nodes. By default <number> = 1
46-
demo: build
47-
CONTIV_HOST_GOBIN=$(HOST_GOBIN) CONTIV_HOST_GOROOT=$(HOST_GOROOT) vagrant up
56+
start: update
57+
CONTIV_NODE_OS=${CONTIV_NODE_OS} vagrant up
58+
59+
demo-centos:
60+
CONTIV_NODE_OS=centos make demo
61+
62+
stop:
63+
CONTIV_NODES=$${CONTIV_NODES:-2} vagrant destroy -f
4864

49-
clean-demo:
50-
vagrant destroy -f
65+
demo: stop start
5166

5267
start-dockerdemo:
5368
scripts/dockerhost/start-dockerhosts
@@ -58,38 +73,41 @@ clean-dockerdemo:
5873
ssh:
5974
@vagrant ssh netplugin-node1 || echo 'Please run "make demo"'
6075

61-
unit-test: build
62-
CONTIV_HOST_GOPATH=$(GOPATH) CONTIV_HOST_GOBIN=$(HOST_GOBIN) \
63-
CONTIV_HOST_GOROOT=$(HOST_GOROOT) ./scripts/unittests -vagrant
76+
unit-test: stop clean build
77+
./scripts/unittests -vagrant
6478

65-
unit-test-centos: build
66-
CONTIV_NODE_OS=centos CONTIV_HOST_GOPATH=$(GOPATH) CONTIV_HOST_GOBIN=$(HOST_GOBIN) \
67-
CONTIV_HOST_GOROOT=$(HOST_GOROOT) ./scripts/unittests -vagrant
79+
unit-test-centos: stop clean
80+
CONTIV_NODE_OS=centos make build
81+
CONTIV_NODE_OS=centos ./scripts/unittests -vagrant
6882

6983
# setting CONTIV_SOE=1 while calling 'make system-test' will stop the test
7084
# on first failure and leave setup in that state. This can be useful for debugging
7185
# as part of development.
72-
system-test: build
73-
CONTIV_HOST_GOROOT=$(HOST_GOROOT) CONTIV_HOST_GOBIN=$(HOST_GOBIN) CONTIV_HOST_GOPATH=$(GOPATH) godep go test --timeout 30m -run "sanity" \
86+
system-test: system-test-singlehost system-test-multihost
87+
88+
# the `make stop` here and below are necessary because build leaves around a VM (intentionally)
89+
system-test-singlehost: stop clean build
90+
make stop
91+
godep go test -v --timeout 30m -run "sanity" \
7492
github.com/contiv/netplugin/systemtests/singlehost
75-
CONTIV_HOST_GOROOT=$(HOST_GOROOT) CONTIV_HOST_GOBIN=$(HOST_GOBIN) CONTIV_HOST_GOPATH=$(GOPATH) godep go test --timeout 80m -run "sanity" \
76-
github.com/contiv/netplugin/systemtests/twohosts
7793

78-
system-test-centos: build
79-
CONTIV_NODE_OS=centos CONTIV_HOST_GOPATH=$(GOPATH) godep go test --timeout 30m -run "sanity" \
80-
github.com/contiv/netplugin/systemtests/singlehost
81-
CONTIV_NODE_OS=centos CONTIV_HOST_GOPATH=$(GOPATH) godep go test --timeout 90m -run "sanity" \
94+
system-test-multihost: stop clean
95+
make build stop
96+
godep go test -v --timeout 80m -run "sanity" \
8297
github.com/contiv/netplugin/systemtests/twohosts
8398

99+
system-test-centos: stop clean
100+
CONTIV_NODE_OS=centos make build stop system-test-singlehost system-test-multihost
101+
84102
centos-tests: unit-test-centos system-test-centos
85103

86104
# setting CONTIV_SOE=1 while calling 'make regress-test' will stop the test
87105
# on first failure and leave setup in that state. This can be useful for debugging
88106
# as part of development.
89107
regress-test: build
90-
CONTIV_HOST_GOPATH=$(GOPATH) godep go test -run "regress" \
108+
godep go test -run "regress" \
91109
github.com/contiv/netplugin/systemtests/singlehost
92-
CONTIV_HOST_GOPATH=$(GOPATH) godep go test --timeout 60m -run "regress" \
110+
godep go test --timeout 60m -run "regress" \
93111
github.com/contiv/netplugin/systemtests/twohosts
94112

95113
# Setting CONTIV_TESTBED=DIND uses docker in docker as the testbed instead of vagrant VMs.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Please do not use this code in production, until code goes through more testing
2020

2121
###Building and Testing
2222

23+
**Note:** Vagrant 1.7.4 and VirtualBox 5.0+ are required to build and test netplugin.
24+
2325
- Build:
2426

2527
`make build`

Vagrantfile

+48-99
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,59 @@
11
# -*- mode: ruby -*-
22
# vi: set ft=ruby :
33

4+
require 'fileutils'
5+
46
netplugin_synced_gopath="/opt/golang"
5-
host_gobin_path="/opt/go/bin"
6-
host_goroot_path="/opt/go/root"
7+
FileUtils.cp "/etc/resolv.conf", Dir.pwd
78

89
provision_common = <<SCRIPT
910
## setup the environment file. Export the env-vars passed as args to 'vagrant up'
1011
echo Args passed: [[ $@ ]]
12+
13+
echo -n "$1" > /etc/hostname
14+
hostname -F /etc/hostname
15+
16+
/sbin/ip addr add "$3/24" dev eth1
17+
/sbin/ip link set eth1 up
18+
/sbin/ip link set eth2 up
19+
1120
echo 'export GOPATH=#{netplugin_synced_gopath}' > /etc/profile.d/envvar.sh
1221
echo 'export GOBIN=$GOPATH/bin' >> /etc/profile.d/envvar.sh
1322
echo 'export GOSRC=$GOPATH/src' >> /etc/profile.d/envvar.sh
14-
echo 'export GOROOT=#{host_goroot_path}' >> /etc/profile.d/envvar.sh
15-
echo 'export PATH=$PATH:#{host_goroot_path}/bin:#{host_gobin_path}:$GOBIN' >> /etc/profile.d/envvar.sh
16-
if [ $# -gt 0 ]; then
17-
echo "export $@" >> /etc/profile.d/envvar.sh
18-
fi
23+
echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> /etc/profile.d/envvar.sh
24+
echo "export http_proxy='$4'" >> /etc/profile.d/envvar.sh
25+
echo "export https_proxy='$5'" >> /etc/profile.d/envvar.sh
26+
echo "export no_proxy=192.168.0.0/16,localhost,127.0.0.0/8" >> /etc/profile.d/envvar.sh
1927
2028
source /etc/profile.d/envvar.sh
2129
22-
## set the mounted host filesystems to be read-only.Just a safety check
23-
## to prevent inadvertent modifications from vm.
24-
(mount -o remount,ro,exec,norelatime /vagrant) || exit 1
25-
if [ -e #{host_gobin_path} ]; then
26-
(mount -o remount,ro,exec,norelatime #{host_gobin_path}) || exit 1
27-
fi
28-
if [ -e #{host_goroot_path} ]; then
29-
(mount -o remount,ro,exec,norelatime #{host_goroot_path}) || exit 1
30-
fi
31-
if [ -e #{netplugin_synced_gopath} ]; then
32-
(mount -o remount,ro,exec,norelatime #{netplugin_synced_gopath}) || exit 1
33-
fi
30+
mv /etc/resolv.conf /etc/resolv.conf.bak
31+
cp #{netplugin_synced_gopath}/src/github.com/contiv/netplugin/resolv.conf /etc/resolv.conf
3432
35-
### install basic packages
36-
#(apt-get update -qq > /dev/null && apt-get install -y vim curl python-software-properties git > /dev/null) || exit 1
37-
#
38-
### install Go 1.4
39-
#(cd /usr/local/ && \
40-
#curl -L https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz -o go1.4.linux-amd64.tar.gz && \
41-
#tar -xzf go1.4.linux-amd64.tar.gz) || exit 1
42-
#
43-
### install etcd
44-
#(cd /tmp && \
45-
#curl -L https://github.com/coreos/etcd/releases/download/v2.0.0/etcd-v2.0.0-linux-amd64.tar.gz -o etcd-v2.0.0-linux-amd64.tar.gz && \
46-
#tar -xzf etcd-v2.0.0-linux-amd64.tar.gz && \
47-
#mv /tmp/etcd-v2.0.0-linux-amd64/etcd /usr/bin/ && \
48-
#mv /tmp/etcd-v2.0.0-linux-amd64/etcdctl /usr/bin/ ) || exit 1
49-
#
50-
### install and start docker
51-
#(curl -sSL https://get.docker.com/ubuntu/ | sh > /dev/null) || exit 1
52-
#
53-
## pass the env-var args to docker and restart the service. This helps passing
54-
## stuff like http-proxy etc
55-
if [ $# -gt 0 ]; then
56-
(echo "export $@" >> /etc/default/docker) || exit 1
33+
mkdir /etc/systemd/system/docker.service.d
34+
echo "[Service]" | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
35+
echo "Environment=\\\"no_proxy=192.168.0.0/16,localhost,127.0.0.0/8\\\" \\\"http_proxy=$http_proxy\\\" \\\"https_proxy=$https_proxy\\\"" | sudo tee -a /etc/systemd/system/docker.service.d/http-proxy.conf
36+
sudo systemctl daemon-reload
37+
sudo systemctl stop docker
38+
sudo systemctl start docker
39+
40+
if [ $# -gt 5 ]; then
41+
shift; shift; shift; shift; shift
42+
echo "export $@" >> /etc/profile.d/envvar.sh
5743
fi
58-
(service docker restart) || exit 1
5944
60-
## install openvswitch and enable ovsdb-server to listen for incoming requests
61-
#(apt-get install -y openvswitch-switch > /dev/null) || exit 1
62-
## Install OVS 2.3.1
63-
# (wget -nv -O ovs-common.deb https://cisco.box.com/shared/static/v1dvgoboo5zgqrtn6tu27vxeqtdo2bdl.deb &&
64-
# wget -nv -O ovs-switch.deb https://cisco.box.com/shared/static/ymbuwvt2qprs4tquextw75b82hyaxwon.deb) || exit 1
65-
# (dpkg -i ovs-common.deb &&
66-
# dpkg -i ovs-switch.deb) || exit 1
45+
(service docker restart) || exit 1
6746
6847
(ovs-vsctl set-manager tcp:127.0.0.1:6640 && \
6948
ovs-vsctl set-manager ptcp:6640) || exit 1
70-
71-
### install consul
72-
#(apt-get install -y unzip && cd /tmp && \
73-
# wget https://dl.bintray.com/mitchellh/consul/0.5.2_linux_amd64.zip && \
74-
# unzip 0.5.2_linux_amd64.zip && \
75-
# mv /tmp/consul /usr/bin) || exit 1
76-
77-
# add vagrant user to docker group
78-
(usermod -a -G docker vagrant)
79-
8049
SCRIPT
8150

8251
VAGRANTFILE_API_VERSION = "2"
8352
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8453
if ENV['CONTIV_NODE_OS'] && ENV['CONTIV_NODE_OS'] == "centos" then
85-
config.vm.box = "contiv/centos"
54+
config.vm.box = "contiv/centos71-netplugin"
8655
else
87-
config.vm.box = "contiv/ubuntu-v4"
56+
config.vm.box = "contiv/ubuntu1504-netplugin"
8857
end
8958
num_nodes = 1
9059
if ENV['CONTIV_NODES'] && ENV['CONTIV_NODES'] != "" then
@@ -93,12 +62,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
9362
base_ip = "192.168.2."
9463
node_ips = num_nodes.times.collect { |n| base_ip + "#{n+10}" }
9564
node_names = num_nodes.times.collect { |n| "netplugin-node#{n+1}" }
65+
node_peers = []
66+
9667
num_nodes.times do |n|
9768
node_name = node_names[n]
9869
node_addr = node_ips[n]
99-
node_peers = ""
100-
node_ips.length.times { |i| node_peers += "#{node_names[i]}=http://#{node_ips[i]}:2380 "}
101-
node_peers = node_peers.strip().gsub(' ', ',')
70+
node_peers += ["#{node_name}=http://#{node_addr}:2380,#{node_name}=http://#{node_addr}:7001"]
10271
consul_join_flag = if n > 0 then "-join #{node_ips[0]}" else "" end
10372
consul_bootstrap_flag = "-bootstrap-expect=3"
10473
if num_nodes < 3 then
@@ -109,11 +78,11 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
10978
end
11079
end
11180
config.vm.define node_name do |node|
112-
node.vm.hostname = node_name
81+
# node.vm.hostname = node_name
11382
# create an interface for etcd cluster
114-
node.vm.network :private_network, ip: node_addr, virtualbox__intnet: "true"
83+
node.vm.network :private_network, ip: node_addr, virtualbox__intnet: "true", auto_config: false
11584
# create an interface for bridged network
116-
node.vm.network :private_network, ip: "0.0.0.0", virtualbox__intnet: "true"
85+
node.vm.network :private_network, ip: "0.0.0.0", virtualbox__intnet: "true", auto_config: false
11786
node.vm.provider "virtualbox" do |v|
11887
# make all nics 'virtio' to take benefit of builtin vlan tag
11988
# support, which otherwise needs to be enabled in Intel drivers,
@@ -125,45 +94,25 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
12594
v.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
12695
end
12796
# mount the host directories
128-
node.vm.synced_folder ".", "/vagrant"
129-
# godep modifies the host's GOPATH env variable, CONTIV_HOST_GOPATH
130-
# contains the unmodified path passed from the Makefile, use that
131-
# when it is defined.
132-
if ENV['CONTIV_HOST_GOPATH'] != nil
133-
node.vm.synced_folder ENV['CONTIV_HOST_GOPATH'], netplugin_synced_gopath
134-
else
135-
node.vm.synced_folder ENV['GOPATH'], netplugin_synced_gopath
136-
end
137-
if ENV['CONTIV_HOST_GOBIN'] != nil
138-
node.vm.synced_folder ENV['CONTIV_HOST_GOBIN'], host_gobin_path
139-
end
140-
if ENV['CONTIV_HOST_GOROOT'] != nil
141-
node.vm.synced_folder ENV['CONTIV_HOST_GOROOT'], host_goroot_path
142-
end
97+
node.vm.synced_folder ".", "/opt/golang/src/github.com/contiv/netplugin"
98+
node.vm.synced_folder File.join(File.dirname(__FILE__), "bin"), File.join(netplugin_synced_gopath, "bin")
99+
143100
node.vm.provision "shell" do |s|
144101
s.inline = provision_common
145-
s.args = ENV['CONTIV_ENV']
102+
s.args = [node_name, ENV["CONTIV_NODE_OS"] || "", node_addr, ENV["http_proxy"] || "", ENV["https_proxy"] || "", *ENV['CONTIV_ENV']]
146103
end
147104
provision_node = <<SCRIPT
148105
## start etcd with generated config
149-
(echo etcd -name #{node_name} -data-dir /opt/etcd \
150-
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
151-
-advertise-client-urls http://#{node_addr}:2379,http://#{node_addr}:4001 \
152-
-initial-advertise-peer-urls http://#{node_addr}:2380 \
153-
-listen-peer-urls http://#{node_addr}:2380 \
154-
-initial-cluster #{node_peers} \
155-
-initial-cluster-state new)
156-
(nohup etcd -name #{node_name} -data-dir /opt/etcd \
157-
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
158-
-advertise-client-urls http://#{node_addr}:2379,http://#{node_addr}:4001 \
159-
-initial-advertise-peer-urls http://#{node_addr}:2380 \
160-
-listen-peer-urls http://#{node_addr}:2380 \
161-
-initial-cluster #{node_peers} \
162-
-initial-cluster-state new 0<&- &>/tmp/etcd.log &) || exit 1
106+
set -x
107+
(nohup etcd --name #{node_name} --data-dir /tmp/etcd \
108+
--listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
109+
--advertise-client-urls http://#{node_addr}:2379,http://#{node_addr}:4001 \
110+
--initial-advertise-peer-urls http://#{node_addr}:2380,http://#{node_addr}:7001 \
111+
--listen-peer-urls http://#{node_addr}:2380 \
112+
--initial-cluster #{node_peers.join(",")} --initial-cluster-state new \
113+
0<&- &>/tmp/etcd.log &) || exit 1
163114
164115
## start consul
165-
(echo && echo consul agent -server #{consul_join_flag} #{consul_bootstrap_flag} \
166-
-bind=#{node_addr} -data-dir /opt/consul)
167116
(nohup consul agent -server #{consul_join_flag} #{consul_bootstrap_flag} \
168117
-bind=#{node_addr} -data-dir /opt/consul 0<&- &>/tmp/consul.log &) || exit 1
169118
SCRIPT

bin/.keep

Whitespace-only changes.

netutils/netutils.go

-34
Original file line numberDiff line numberDiff line change
@@ -211,40 +211,6 @@ func ParseTagRanges(ranges string, tagType string) ([]TagRange, error) {
211211
return tagRanges, nil
212212
}
213213

214-
// GetLocalIP obtains the first IP on a local interface on the host.
215-
func GetLocalIP() (string, error) {
216-
var addrs []netlink.Addr
217-
localIPAddr := ""
218-
219-
for idx := 0; idx < 3; idx++ {
220-
linkName := "eth" + strconv.Itoa(idx)
221-
link, err := netlink.LinkByName(linkName)
222-
if err != nil {
223-
if strings.Contains(err.Error(), "Link not found") {
224-
continue
225-
}
226-
return "", err
227-
}
228-
addrs, err = netlink.AddrList(link, netlink.FAMILY_V4)
229-
if err != nil {
230-
if strings.Contains(err.Error(), "Link not found") {
231-
continue
232-
}
233-
return "", err
234-
}
235-
if len(addrs) > 0 {
236-
localIPAddr = addrs[0].IP.String()
237-
}
238-
}
239-
240-
err := core.Errorf("local ip not found")
241-
if localIPAddr != "" {
242-
err = nil
243-
}
244-
245-
return localIPAddr, err
246-
}
247-
248214
// ParseCIDR parses a CIDR string into a gateway IP and length.
249215
func ParseCIDR(cidrStr string) (string, uint, error) {
250216
strs := strings.Split(cidrStr, "/")

netutils/netutils_test.go

-7
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,3 @@ func TestGetSubnetNumber(t *testing.T) {
196196
}
197197
}
198198
}
199-
200-
func TestGetLocalIP(t *testing.T) {
201-
ipAddr, err := GetLocalIP()
202-
if ipAddr == "" {
203-
t.Fatalf("error obtaining local IP of the host '%s' \n", err)
204-
}
205-
}

scripts/unittests

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ done
3636

3737
# running on host
3838
if ${run_in_vagrant}; then
39-
(CONTIV_NODES=1 vagrant up)
39+
(CONTIV_NODE_OS="${CONTIV_NODE_OS}" CONTIV_NODES=1 vagrant up)
4040
ret=$?
4141
if [ ${ret} -ne 0 ]; then
4242
(CONTIV_NODES=1 vagrant destroy -f)

0 commit comments

Comments
 (0)