Skip to content

Commit cda0524

Browse files
committed
Mount and use host's go environment in the vagrant vm
Changes involve mountiing the host's go binary and root directories in the vagrant vm, to allow 'go test' run in the vm using same environment as the host's build environment. This allows to relax the strict version check for host go version.
1 parent dc3007a commit cda0524

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.PHONY: all build clean default system-test unit-test
22

33
TO_BUILD := ./ ./netdcli/
4+
HOST_GOBIN := `which go | xargs dirname`
5+
HOST_GOROOT := `go env GOROOT`
46

57
all: build unit-test system-test
68

@@ -14,14 +16,16 @@ build:
1416
clean:
1517
go clean -i -v ./...
1618

19+
# setting CONTIV_NODES=<number> while calling 'make demo' can be used to bring
20+
# up a cluster of <number> nodes. By default <number> = 1
1721
demo: build
18-
CONTIV_ENV="$(CONTIV_ENV)" CONTIV_NODES=$(CONTIV_NODES) vagrant up
22+
CONTIV_HOST_GOBIN=$(HOST_GOBIN) CONTIV_HOST_GOROOT=$(HOST_GOROOT) vagrant up
1923

2024
clean-demo:
21-
CONTIV_NODES=$(CONTIV_NODES) vagrant destroy -f
25+
vagrant destroy -f
2226

2327
unit-test: build
24-
./scripts/unittests -vagrant
28+
CONTIV_HOST_GOBIN=$(HOST_GOBIN) CONTIV_HOST_GOROOT=$(HOST_GOROOT) ./scripts/unittests -vagrant
2529

2630
system-test: build
2731
go test -v -run "sanity" github.com/contiv/netplugin/systemtests/singlehost

Vagrantfile

+19-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22
# vi: set ft=ruby :
33

44
netplugin_synced_gopath="/opt/golang"
5+
host_gobin_path="/opt/go/bin"
6+
host_goroot_path="/opt/go/root"
57

68
provision_common = <<SCRIPT
79
## setup the environment file. Export the env-vars passed as args to 'vagrant up'
810
echo Args passed: [[ $@ ]]
911
echo 'export GOPATH=#{netplugin_synced_gopath}' > /etc/profile.d/envvar.sh
1012
echo 'export GOBIN=$GOPATH/bin' >> /etc/profile.d/envvar.sh
1113
echo 'export GOSRC=$GOPATH/src' >> /etc/profile.d/envvar.sh
12-
echo 'export PATH=$PATH:/usr/local/go/bin:$GOBIN' >> /etc/profile.d/envvar.sh
14+
echo 'export GOROOT=#{host_goroot_path}' >> /etc/profile.d/envvar.sh
15+
echo 'export PATH=$PATH:#{host_gobin_path}:$GOBIN' >> /etc/profile.d/envvar.sh
1316
if [ $# -gt 0 ]; then
1417
echo "export $@" >> /etc/profile.d/envvar.sh
1518
fi
1619
17-
## set the mounted host filesystems to be read-only
20+
## set the mounted host filesystems to be read-only.Just a safety check
21+
## to prevent inadvertent modifications from vm.
1822
(mount -o remount,ro,exec /vagrant) || exit 1
23+
if [ -e #{host_gobin_path} ]; then
24+
(mount -o remount,ro,exec #{host_gobin_path}) || exit 1
25+
fi
26+
if [ -e #{host_goroot_path} ]; then
27+
(mount -o remount,ro,exec #{host_goroot_path}) || exit 1
28+
fi
1929
if [ -e #{netplugin_synced_gopath} ]; then
2030
(mount -o remount,ro,exec #{netplugin_synced_gopath}) || exit 1
2131
fi
@@ -86,15 +96,15 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8696
v.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
8797
v.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
8898
end
89-
# mount host filesystems as read only since these files potentially
90-
# get shared between multiple vms. Just a safety check to prevent
91-
# inadvertent modifications. XXX: This doesn't seem to be working,
92-
# so will remount the parition as part of provisioning later and
93-
# change options
94-
#node.vm.synced_folder ".", "/vagrant", mount_options: ["ro", "exec"]
95-
#node.vm.synced_folder ENV['GOPATH'], netplugin_synced_gopath, mount_options: ["ro", "exec"]
99+
# mount the host directories
96100
node.vm.synced_folder ".", "/vagrant"
97101
node.vm.synced_folder ENV['GOPATH'], netplugin_synced_gopath
102+
if ENV['CONTIV_HOST_GOBIN'] != nil
103+
node.vm.synced_folder ENV['CONTIV_HOST_GOBIN'], host_gobin_path
104+
end
105+
if ENV['CONTIV_HOST_GOROOT'] != nil
106+
node.vm.synced_folder ENV['CONTIV_HOST_GOROOT'], host_goroot_path
107+
end
98108
node.vm.provision "shell" do |s|
99109
s.inline = provision_common
100110
s.args = ENV['CONTIV_ENV']

scripts/checks

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
echo "Checking Go version..."
66
ver=$(go version | awk '{print $3}')
7-
expVer="go1.4"
8-
if [[ ${ver} != ${expVer} ]]; then
9-
echo "Go version check failed. Expected ${expVer} but found ${ver}"
7+
minVer="go1.4"
8+
if [[ ${ver} < ${minVer} ]]; then
9+
echo "Go version check failed. Expected >=${minVer} but found ${ver}"
1010
exit 1
1111
fi
1212

scripts/unittests

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ done
3131

3232
# running on host
3333
if ${run_in_vagrant}; then
34-
(CONTIV_NODES=1 CONTIV_ENV=$CONTIV_ENV vagrant up)
34+
(CONTIV_NODES=1 vagrant up)
3535
ret=$?
3636
if [ ${ret} -ne 0 ]; then
3737
(CONTIV_NODES=1 vagrant destroy -f)

0 commit comments

Comments
 (0)