Skip to content

Commit d0276e9

Browse files
committed
Mount and use host's go binary in the vagrant vm
This allows to relax the strict version check for host go version.
1 parent dc3007a commit d0276e9

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

Makefile

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ build:
1414
clean:
1515
go clean -i -v ./...
1616

17+
# setting CONTIV_NODES=<number> while calling 'make demo' can be used to bring
18+
# up a cluster of <number> nodes. By default <number> = 1
1719
demo: build
18-
CONTIV_ENV="$(CONTIV_ENV)" CONTIV_NODES=$(CONTIV_NODES) vagrant up
20+
CONTIV_HOST_GOBIN=`which go | xargs dirname` vagrant up
1921

2022
clean-demo:
21-
CONTIV_NODES=$(CONTIV_NODES) vagrant destroy -f
23+
vagrant destroy -f
2224

2325
unit-test: build
24-
./scripts/unittests -vagrant
26+
CONTIV_HOST_GOBIN=`which go | xargs dirname` ./scripts/unittests -vagrant
2527

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

Vagrantfile

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

44
netplugin_synced_gopath="/opt/golang"
5+
host_gobin_path="/opt/go/bin"
56

67
provision_common = <<SCRIPT
78
## setup the environment file. Export the env-vars passed as args to 'vagrant up'
89
echo Args passed: [[ $@ ]]
910
echo 'export GOPATH=#{netplugin_synced_gopath}' > /etc/profile.d/envvar.sh
1011
echo 'export GOBIN=$GOPATH/bin' >> /etc/profile.d/envvar.sh
1112
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
13+
echo 'export PATH=$PATH:#{host_gobin_path}:$GOBIN' >> /etc/profile.d/envvar.sh
1314
if [ $# -gt 0 ]; then
1415
echo "export $@" >> /etc/profile.d/envvar.sh
1516
fi
1617
17-
## set the mounted host filesystems to be read-only
18+
## set the mounted host filesystems to be read-only.Just a safety check
19+
## to prevent inadvertent modifications from vm.
1820
(mount -o remount,ro,exec /vagrant) || exit 1
21+
if [ -e #{host_gobin_path} ]; then
22+
(mount -o remount,ro,exec #{host_gobin_path}) || exit 1
23+
fi
1924
if [ -e #{netplugin_synced_gopath} ]; then
2025
(mount -o remount,ro,exec #{netplugin_synced_gopath}) || exit 1
2126
fi
@@ -86,15 +91,12 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
8691
v.customize ['modifyvm', :id, '--nicpromisc2', 'allow-all']
8792
v.customize ['modifyvm', :id, '--nicpromisc3', 'allow-all']
8893
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"]
94+
# mount the host directories
9695
node.vm.synced_folder ".", "/vagrant"
9796
node.vm.synced_folder ENV['GOPATH'], netplugin_synced_gopath
97+
if ENV['CONTIV_HOST_GOBIN'] != nil
98+
node.vm.synced_folder ENV['CONTIV_HOST_GOBIN'], host_gobin_path
99+
end
98100
node.vm.provision "shell" do |s|
99101
s.inline = provision_common
100102
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)