Skip to content

Commit

Permalink
Support running integration tests in local vagrant VM.
Browse files Browse the repository at this point in the history
  • Loading branch information
shishir-a412ed committed Jan 28, 2021
1 parent d1c51d3 commit 35dc902
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 39 deletions.
19 changes: 11 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
config.vm.define "containerd-linux"
config.vm.box = "hashicorp/bionic64"
config.vm.synced_folder ".", "/home/vagrant/go/src/nomad-driver-containerd"
config.ssh.extra_args = ["-t", "cd /home/vagrant/go/src/nomad-driver-containerd; bash --login"]
config.vm.synced_folder ".", "/home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd"
config.ssh.extra_args = ["-t", "cd /home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd; bash --login"]
config.vm.network "forwarded_port", guest: 4646, host: 4646, host_ip: "127.0.0.1"
config.vm.provider "virtualbox" do |vb|
vb.name = "containerd-linux"
Expand All @@ -16,7 +16,7 @@ Vagrant.configure("2") do |config|
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y unzip gcc runc
apt-get install -y unzip gcc runc jq
echo "export GOPATH=/home/vagrant/go" >> /home/vagrant/.bashrc
echo "export PATH=$PATH:/usr/local/go/bin" >> /home/vagrant/.bashrc
source /home/vagrant/.bashrc
Expand All @@ -29,12 +29,12 @@ Vagrant.configure("2") do |config|
rm -f go1.14.3.linux-amd64.tar.gz
fi
# Install nomad-0.11.3
# Install nomad-1.0.2
if [ ! -f "/usr/bin/nomad" ]; then
wget --quiet https://releases.hashicorp.com/nomad/0.11.3/nomad_0.11.3_linux_amd64.zip
unzip nomad_0.11.3_linux_amd64.zip -d /usr/bin
wget --quiet https://releases.hashicorp.com/nomad/1.0.2/nomad_1.0.2_linux_amd64.zip
unzip nomad_1.0.2_linux_amd64.zip -d /usr/bin
chmod +x /usr/bin/nomad
rm -f nomad_0.11.3_linux_amd64.zip
rm -f nomad_1.0.2_linux_amd64.zip
fi
# Install containerd-1.3.4
Expand All @@ -47,8 +47,11 @@ Vagrant.configure("2") do |config|
# Create source directory for privileged.nomad example job.
mkdir -p /tmp/s1
# Prepare nomad host volume
mkdir -p /tmp/host_volume/s1
# Run setup
cd /home/vagrant/go/src/nomad-driver-containerd/vagrant
cd /home/vagrant/go/src/github.com/Roblox/nomad-driver-containerd/vagrant
./setup.sh
SHELL
end
7 changes: 7 additions & 0 deletions example/agent.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@ plugin "containerd-driver" {
stats_interval = "5s"
}
}

client {
host_volume "s1" {
path = "/tmp/host_volume/s1"
read_only = false
}
}
16 changes: 0 additions & 16 deletions example/agent_tests.hcl

This file was deleted.

22 changes: 11 additions & 11 deletions tests/003-test-capabilities.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ test_capabilities_nomad_job() {
exit 1
fi

# Check if readonly_rootfs is set to true.
echo "INFO: Checking if readonly_rootfs is set to true."
local outfile=$(mktemp /tmp/capabilities.XXXXXX)
nomad alloc exec -job capabilities touch /tmp/file.txt >> $outfile 2>&1
if ! grep -q "Read-only file system" $outfile; then
echo "ERROR: readonly_rootfs is not set to true."
cleanup "$outfile"
exit 1
fi
cleanup "$outfile"

# Check if CAP_SYS_ADMIN was added.
echo "INFO: Checking if CAP_SYS_ADMIN is added."
nomad alloc exec -job capabilities capsh --print|grep cap_sys_admin >/dev/null 2>&1
Expand All @@ -56,6 +45,17 @@ test_capabilities_nomad_job() {
exit 1
fi

# Check if readonly_rootfs is set to true.
echo "INFO: Checking if readonly_rootfs is set to true."
local outfile=$(mktemp /tmp/capabilities.XXXXXX)
nomad alloc exec -job capabilities touch /tmp/file.txt >> $outfile 2>&1
if ! grep -q "Read-only file system" $outfile; then
echo "ERROR: readonly_rootfs is not set to true."
cleanup "$outfile"
exit 1
fi
cleanup "$outfile"

echo "INFO: Stopping nomad capabilities job."
nomad job stop capabilities
cap_status=$(nomad job status -short capabilities|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ')
Expand Down
13 changes: 10 additions & 3 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PASS_STATUS=0
# These tests are designed to be run as part of continous integration (CI) and not on local host.
# Please don't run these tests (./run_tests.sh) on your local host, as these are meant to be
# destructive and can modify (or destroy) software on your host system.
# If you are running the tests locally, run it in the vagrant VM provided with the repository.
main() {
warn_on_local_host
setup
Expand Down Expand Up @@ -62,6 +63,7 @@ warn_on_local_host() {
echo "WARNING: Local host detected."
echo "WARNING: These tests are designed to be run as part of continous integration (CI) and not recommended to be run on local host."
echo "WARNING: These tests are destructive and can modify (or destroy) software on your host system."
echo "WARNING: If running the tests locally, run it in the vagrant VM provided with the repository."
read -p "Do you still want to run the tests (Y/N)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
Expand All @@ -72,7 +74,12 @@ warn_on_local_host() {
}

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

sudo systemctl stop apt-daily-upgrade apt-daily >/dev/null 2>&1

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

# Install nomad 0.11.2
# Install nomad 1.0.2
curl -L -o nomad_${NOMAD_VERSION}_linux_amd64.zip https://releases.hashicorp.com/nomad/${NOMAD_VERSION}/nomad_${NOMAD_VERSION}_linux_amd64.zip
sudo unzip -d /usr/local/bin nomad_${NOMAD_VERSION}_linux_amd64.zip
sudo chmod +x /usr/local/bin/nomad
Expand All @@ -156,7 +163,7 @@ Documentation=https://nomadproject.io
After=network.target
[Service]
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
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
KillMode=process
Delegate=yes
LimitNOFILE=1048576
Expand Down
2 changes: 1 addition & 1 deletion vagrant/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ main() {
echo "WARN: Some installation steps are time consuming. Please be patient!"

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

0 comments on commit 35dc902

Please sign in to comment.