Skip to content

Commit 35dc902

Browse files
Support running integration tests in local vagrant VM.
1 parent d1c51d3 commit 35dc902

File tree

6 files changed

+40
-39
lines changed

6 files changed

+40
-39
lines changed

Vagrantfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ VAGRANTFILE_API_VERSION = "2"
66
Vagrant.configure("2") do |config|
77
config.vm.define "containerd-linux"
88
config.vm.box = "hashicorp/bionic64"
9-
config.vm.synced_folder ".", "/home/vagrant/go/src/nomad-driver-containerd"
10-
config.ssh.extra_args = ["-t", "cd /home/vagrant/go/src/nomad-driver-containerd; bash --login"]
9+
config.vm.synced_folder ".", "/home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd"
10+
config.ssh.extra_args = ["-t", "cd /home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd; bash --login"]
1111
config.vm.network "forwarded_port", guest: 4646, host: 4646, host_ip: "127.0.0.1"
1212
config.vm.provider "virtualbox" do |vb|
1313
vb.name = "containerd-linux"
@@ -16,7 +16,7 @@ Vagrant.configure("2") do |config|
1616
end
1717
config.vm.provision "shell", inline: <<-SHELL
1818
apt-get update
19-
apt-get install -y unzip gcc runc
19+
apt-get install -y unzip gcc runc jq
2020
echo "export GOPATH=/home/vagrant/go" >> /home/vagrant/.bashrc
2121
echo "export PATH=$PATH:/usr/local/go/bin" >> /home/vagrant/.bashrc
2222
source /home/vagrant/.bashrc
@@ -29,12 +29,12 @@ Vagrant.configure("2") do |config|
2929
rm -f go1.14.3.linux-amd64.tar.gz
3030
fi
3131
32-
# Install nomad-0.11.3
32+
# Install nomad-1.0.2
3333
if [ ! -f "/usr/bin/nomad" ]; then
34-
wget --quiet https://releases.hashicorp.com/nomad/0.11.3/nomad_0.11.3_linux_amd64.zip
35-
unzip nomad_0.11.3_linux_amd64.zip -d /usr/bin
34+
wget --quiet https://releases.hashicorp.com/nomad/1.0.2/nomad_1.0.2_linux_amd64.zip
35+
unzip nomad_1.0.2_linux_amd64.zip -d /usr/bin
3636
chmod +x /usr/bin/nomad
37-
rm -f nomad_0.11.3_linux_amd64.zip
37+
rm -f nomad_1.0.2_linux_amd64.zip
3838
fi
3939
4040
# Install containerd-1.3.4
@@ -47,8 +47,11 @@ Vagrant.configure("2") do |config|
4747
# Create source directory for privileged.nomad example job.
4848
mkdir -p /tmp/s1
4949
50+
# Prepare nomad host volume
51+
mkdir -p /tmp/host_volume/s1
52+
5053
# Run setup
51-
cd /home/vagrant/go/src/nomad-driver-containerd/vagrant
54+
cd /home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd/vagrant
5255
./setup.sh
5356
SHELL
5457
end

example/agent.hcl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ plugin "containerd-driver" {
77
stats_interval = "5s"
88
}
99
}
10+
11+
client {
12+
host_volume "s1" {
13+
path = "/tmp/host_volume/s1"
14+
read_only = false
15+
}
16+
}

example/agent_tests.hcl

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/003-test-capabilities.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ test_capabilities_nomad_job() {
2727
exit 1
2828
fi
2929

30-
# Check if readonly_rootfs is set to true.
31-
echo "INFO: Checking if readonly_rootfs is set to true."
32-
local outfile=$(mktemp /tmp/capabilities.XXXXXX)
33-
nomad alloc exec -job capabilities touch /tmp/file.txt >> $outfile 2>&1
34-
if ! grep -q "Read-only file system" $outfile; then
35-
echo "ERROR: readonly_rootfs is not set to true."
36-
cleanup "$outfile"
37-
exit 1
38-
fi
39-
cleanup "$outfile"
40-
4130
# Check if CAP_SYS_ADMIN was added.
4231
echo "INFO: Checking if CAP_SYS_ADMIN is added."
4332
nomad alloc exec -job capabilities capsh --print|grep cap_sys_admin >/dev/null 2>&1
@@ -56,6 +45,17 @@ test_capabilities_nomad_job() {
5645
exit 1
5746
fi
5847

48+
# Check if readonly_rootfs is set to true.
49+
echo "INFO: Checking if readonly_rootfs is set to true."
50+
local outfile=$(mktemp /tmp/capabilities.XXXXXX)
51+
nomad alloc exec -job capabilities touch /tmp/file.txt >> $outfile 2>&1
52+
if ! grep -q "Read-only file system" $outfile; then
53+
echo "ERROR: readonly_rootfs is not set to true."
54+
cleanup "$outfile"
55+
exit 1
56+
fi
57+
cleanup "$outfile"
58+
5959
echo "INFO: Stopping nomad capabilities job."
6060
nomad job stop capabilities
6161
cap_status=$(nomad job status -short capabilities|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')

tests/run_tests.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PASS_STATUS=0
2121
# These tests are designed to be run as part of continous integration (CI) and not on local host.
2222
# Please don't run these tests (./run_tests.sh) on your local host, as these are meant to be
2323
# destructive and can modify (or destroy) software on your host system.
24+
# If you are running the tests locally, run it in the vagrant VM provided with the repository.
2425
main() {
2526
warn_on_local_host
2627
setup
@@ -62,6 +63,7 @@ warn_on_local_host() {
6263
echo "WARNING: Local host detected."
6364
echo "WARNING: These tests are designed to be run as part of continous integration (CI) and not recommended to be run on local host."
6465
echo "WARNING: These tests are destructive and can modify (or destroy) software on your host system."
66+
echo "WARNING: If running the tests locally, run it in the vagrant VM provided with the repository."
6567
read -p "Do you still want to run the tests (Y/N)? " -n 1 -r
6668
echo
6769
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
@@ -72,7 +74,12 @@ warn_on_local_host() {
7274
}
7375

7476
setup() {
75-
sudo systemctl stop apt-daily-upgrade apt-daily >/dev/null 2>&1
77+
if [[ -z "$CIRCLECI" || "$CIRCLECI" != "true" ]]; then
78+
echo "INFO: Running tests on local host (vagrant VM). Setup is not required."
79+
return 0
80+
fi
81+
82+
sudo systemctl stop apt-daily-upgrade apt-daily >/dev/null 2>&1
7683

7784
set +e
7885
sudo pkill --signal SIGKILL -P $(ps faux | grep 'daily' | awk '{print $2}')
@@ -134,7 +141,7 @@ EOF
134141
sudo chmod +x /usr/local/go
135142
rm -f go${GO_VERSION}.linux-amd64.tar.gz
136143

137-
# Install nomad 0.11.2
144+
# Install nomad 1.0.2
138145
curl -L -o nomad_${NOMAD_VERSION}_linux_amd64.zip https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip
139146
sudo unzip -d /usr/local/bin nomad_${NOMAD_VERSION}_linux_amd64.zip
140147
sudo chmod +x /usr/local/bin/nomad
@@ -156,7 +163,7 @@ Documentation=https://nomadproject.io
156163
After=network.target
157164
158165
[Service]
159-
ExecStart=/usr/local/bin/nomad agent -dev -config=$GOPATH/src/github.com/Roblox/nomad-driver-containerd/example/agent_tests.hcl -plugin-dir=/tmp/nomad-driver-containerd
166+
ExecStart=/usr/local/bin/nomad agent -dev -config=$GOPATH/src/github.com/Roblox/nomad-driver-containerd/example/agent.hcl -plugin-dir=/tmp/nomad-driver-containerd
160167
KillMode=process
161168
Delegate=yes
162169
LimitNOFILE=1048576

vagrant/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ main() {
77
echo "WARN: Some installation steps are time consuming. Please be patient!"
88

99
# Save project root directory.
10-
root_dir="/home/vagrant/go/src/nomad-driver-containerd"
10+
root_dir="/home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd"
1111
pushd $root_dir >/dev/null 2>&1
1212
echo "INFO: Drop systemd unit containerd.service into /lib/systemd/system/containerd.service."
1313
drop_containerd_unit_file

0 commit comments

Comments
 (0)