aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject git commit: Add a test to validate that the tutorial instructions work.
Date Wed, 09 Apr 2014 22:17:40 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master f73e29b31 -> 0f3ce5f44


Add a test to validate that the tutorial instructions work.

Bugs closed: AURORA-299

Reviewed at https://reviews.apache.org/r/20067/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/0f3ce5f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/0f3ce5f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/0f3ce5f4

Branch: refs/heads/master
Commit: 0f3ce5f4412a338468242f005c67a0081a99a092
Parents: f73e29b
Author: Bill Farner <wfarner@apache.org>
Authored: Wed Apr 9 15:17:34 2014 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Wed Apr 9 15:17:34 2014 -0700

----------------------------------------------------------------------
 docs/tutorial.md                                |   4 +
 examples/vagrant/test_tutorial.sh               | 127 +++++++++++++++++++
 .../upstart/aurora-thermos-observer.conf        |   2 +-
 3 files changed, 132 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0f3ce5f4/docs/tutorial.md
----------------------------------------------------------------------
diff --git a/docs/tutorial.md b/docs/tutorial.md
index e428f4e..64981a7 100644
--- a/docs/tutorial.md
+++ b/docs/tutorial.md
@@ -46,6 +46,8 @@ this directory is the same as `/vagrant` inside the Vagrant VMs).
 
 The script has an intentional bug, which we will explain later on.
 
+<!-- NOTE: If you are changing this file, be sure to also update examples/vagrant/test_tutorial.sh.
+-->
 ```python
 import sys
 import time
@@ -69,6 +71,8 @@ Once we have our script/program, we need to create a *configuration
 file* that tells Aurora how to manage and launch our Job. Save the below
 code in the file `hello_world.aurora`.
 
+<!-- NOTE: If you are changing this file, be sure to also update examples/vagrant/test_tutorial.sh.
+-->
 ```python
 pkg_path = '/vagrant/hello_world.py'
 

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0f3ce5f4/examples/vagrant/test_tutorial.sh
----------------------------------------------------------------------
diff --git a/examples/vagrant/test_tutorial.sh b/examples/vagrant/test_tutorial.sh
new file mode 100644
index 0000000..1b745b8
--- /dev/null
+++ b/examples/vagrant/test_tutorial.sh
@@ -0,0 +1,127 @@
+#!/bin/bash
+set -o nounset
+
+# Tests the basic functions described in docs/tutorial.md
+# Note that this script has copy-pasted contents of hello_world.py
+# and hello_world.aurora. These files must be manually kept in sync.
+
+function require_healthy {
+  echo "Checking $1 health...\c"
+  response=$(curl -sL -w "%{http_code}\\n" "http://$2/health" -o /dev/null)
+  if [ "$response" == '200' ]
+  then
+    echo 'PASS'
+  else
+    echo 'FAIL'
+    echo "The $1 did not respond to a health check, is it running?"
+    exit 1
+  fi
+}
+
+function write_test_files {
+  cat > hello_world.py <<EOF
+import sys
+import time
+
+def main(argv):
+  SLEEP_DELAY = 10
+  # Python ninjas - ignore this blatant bug.
+  for i in xrang(100):
+    print("Hello world! The time is now: %s. Sleeping for %d secs" % (
+      time.asctime(), SLEEP_DELAY))
+    sys.stdout.flush()
+    time.sleep(SLEEP_DELAY)
+
+if __name__ == "__main__":
+  main(sys.argv)
+EOF
+
+  cat > hello_world.aurora <<EOF
+pkg_path = '/vagrant/hello_world.py'
+
+# we use a trick here to make the configuration change with
+# the contents of the file, for simplicity.  in a normal setting, packages would be
+# versioned, and the version number would be changed in the configuration.
+import hashlib
+with open(pkg_path, 'rb') as f:
+  pkg_checksum = hashlib.md5(f.read()).hexdigest()
+
+# copy hello_world.py into the local sandbox
+install = Process(
+  name = 'fetch_package',
+  cmdline = 'cp %s . && echo %s && chmod +x hello_world.py' % (pkg_path,
pkg_checksum))
+
+# run the script
+hello_world = Process(
+  name = 'hello_world',
+  cmdline = 'python hello_world.py')
+
+# describe the task
+hello_world_task = SequentialTask(
+  processes = [install, hello_world],
+  resources = Resources(cpu = 1, ram = 1*MB, disk=8*MB))
+
+jobs = [
+  Service(cluster = 'devcluster',
+          environment = 'devel',
+          role = 'www-data',
+          name = 'hello_world',
+          task = hello_world_task)
+]
+EOF
+}
+
+function aurora_command {
+  echo "Running $1 command...\c"
+  result=$(vagrant ssh -c "aurora $2" 2>&1)
+  if [ $? -eq 0 ]
+  then
+    echo 'PASS'
+  else
+    echo 'FAIL'
+    echo "Command output:\n$result"
+    exit 1
+  fi
+}
+
+function await_task_in_state {
+  echo "Waiting to observe $2 task...\c"
+  for i in $(seq 0 5)
+  do
+    # TODO(wfarner): This check is not that great, since it will detect any task
+    # in the job, rather a newly-failed task.
+    result=$(vagrant ssh -c "aurora status $1 2>&1 | grep 'status: $2'" 2>&1)
+    if [ $? -eq 0 ]
+    then
+      echo 'PASS'
+      return
+    else
+      sleep 2
+    fi
+  done
+  echo 'FAIL'
+  echo "Command output:\n$result"
+}
+
+require_healthy scheduler 192.168.33.7:8081
+require_healthy observer 192.168.33.7:1338
+require_healthy master 192.168.33.7:5050/master
+require_healthy slave '192.168.33.7:5051/slave(1)'
+
+# Move to repository root
+cd "$(git rev-parse --show-toplevel)"
+
+JOB_KEY=devcluster/www-data/devel/hello_world
+
+write_test_files
+aurora_command create "create $JOB_KEY /vagrant/hello_world.aurora"
+await_task_in_state $JOB_KEY FAILED
+
+# Fix the bug in our test script.
+sed -i '' 's/xrang(/xrange(/' hello_world.py
+aurora_command update "update $JOB_KEY /vagrant/hello_world.aurora"
+await_task_in_state $JOB_KEY RUNNING
+
+aurora_command killall "killall $JOB_KEY"
+
+exit 0
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0f3ce5f4/examples/vagrant/upstart/aurora-thermos-observer.conf
----------------------------------------------------------------------
diff --git a/examples/vagrant/upstart/aurora-thermos-observer.conf b/examples/vagrant/upstart/aurora-thermos-observer.conf
index 6db85aa..04e4cb6 100644
--- a/examples/vagrant/upstart/aurora-thermos-observer.conf
+++ b/examples/vagrant/upstart/aurora-thermos-observer.conf
@@ -17,7 +17,7 @@ start on stopped rc RUNLEVEL=[2345]
 respawn
 post-stop exec sleep 5
 
-exec /usr/local/aurora/bin/thermos_observer \
+exec /home/vagrant/aurora/dist/thermos_observer.pex \
   --root=/var/run/thermos \
   --port=1338 \
   --log_to_disk=NONE \


Mime
View raw message