Last active
January 16, 2018 14:04
-
-
Save hobochili/c714d246d20b8b3c0bf985b2b9a54b5a to your computer and use it in GitHub Desktop.
Nomad auto-revert test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/bash | |
# Creates a stable test job with auto_revert=true in Nomad, | |
# updates it a bunch of times to force the job version to 256, | |
# then creates an unstable job. Nomad will roll back to 255 | |
# instead of 256. | |
sudo tee /tmp/pass.nomad << EOF > /dev/null | |
job "test" { | |
datacenters = ["dc1"] | |
region = "global" | |
type = "service" | |
update { | |
health_check = "task_states" | |
min_healthy_time = "1s" | |
healthy_deadline = "5s" | |
auto_revert = "true" | |
} | |
group "pass" { | |
count = 1 | |
task "tail" { | |
driver = "exec" | |
config { | |
command = "tail" | |
args = [ | |
"-f", "/dev/null", | |
] | |
} | |
} | |
} | |
} | |
EOF | |
sudo tee /tmp/fail.nomad << EOF > /dev/null | |
job "test" { | |
datacenters = ["dc1"] | |
region = "global" | |
type = "service" | |
update { | |
health_check = "task_states" | |
min_healthy_time = "1s" | |
healthy_deadline = "5s" | |
auto_revert = "true" | |
} | |
group "fail" { | |
count = 1 | |
task "tail" { | |
driver = "exec" | |
config { | |
command = "tail" | |
args = [ | |
"-f", "/dev/DNE", | |
] | |
} | |
} | |
} | |
} | |
EOF | |
ver=0 | |
while [ $ver -lt 256 ]; do | |
echo "Version: $ver" | |
sed -E "s/ task \"tail(_[0-9])?[0-9]*\" \{/ task \"tail_${ver}\" \{/" /tmp/pass.nomad > /tmp/test.nomad | |
nomad run /tmp/test.nomad | |
stable=$(nomad job history -json -version $ver test 2>/dev/null | jq '.Stable') | |
while [ "$stable" != "true" ]; do | |
stable=$(nomad job history -json -version $ver test 2>/dev/null | jq '.Stable') | |
done | |
ver=$(($ver+1)) | |
done | |
# Create stable version 256 | |
sed -E "s/ task \"tail(_[0-9])?[0-9]*\" \{/ task \"tail_256\" \{/" /tmp/pass.nomad > /tmp/test.nomad | |
nomad run /tmp/test.nomad | |
nomad deployment list | head | |
nomad job status test | |
nomad job history test | |
# Create unstable version 257 | |
nomad run /tmp/fail.nomad | |
sleep 5 | |
# Note that it rolls back to 255 instead of 256 | |
nomad deployment list | head | |
nomad job status test | |
nomad job history test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment