From 0f3660dc95eb3128856d21692ba3143d70eaae68 Mon Sep 17 00:00:00 2001 From: AJ Bowen Date: Sun, 29 Oct 2017 15:01:24 -0700 Subject: [PATCH] Put 'wait' and 'keys' HTML comments before the command they apply to. Add colored logs. --- autotest/autotest.py | 38 ++++++++++++++++++++++++++++--- docs/sampleapp.md | 50 +++++++++++++++++++++++++---------------- prepare-vms/workshopctl | 3 +++ 3 files changed, 69 insertions(+), 22 deletions(-) diff --git a/autotest/autotest.py b/autotest/autotest.py index ad376f5c..26d6b03f 100755 --- a/autotest/autotest.py +++ b/autotest/autotest.py @@ -7,6 +7,9 @@ import subprocess import sys import time +import coloredlogs, logging +coloredlogs.install() + logging.basicConfig(level=logging.DEBUG) def hrule(): @@ -95,25 +98,45 @@ except Exception as e: keymaps = { "^C": "\x03" } -def wait_for_success(): +def wait_for_success(wait_for=None): secs, timeout = 0, 30 while secs <= timeout: time.sleep(1) output = [x for x in subprocess.check_output(["tmux", "capture-pane", "-p"]).split("\n") if x] + if wait_for and [x for x in output if wait_for in x]: + return True if output[-1] == "$": return True else: print(".") secs += 1 +wait_for, action, method = "", "", "" while True: with open("nextstep","w") as f: f.write(str(i)) slide, snippet, method, data = actions[i] data = data.strip() + + # Look behind at the last slide to see if 'wait' or 'keys' was defined. + # If so, we need to wait for the specified output and/or terminate the command with the specified keys. + if method == "wait": + wait_for = data + print("Setting wait_for to: {}".format(data)) + i += 1 + continue + if method == "keys": + action = data + print("Setting action to: {}".format(data)) + i += 1 + continue print(hrule()) print(slide.content.replace(snippet.content, ansi(7)(snippet.content))) print(hrule()) + if wait_for: + print("waiting for: {}".format(wait_for)) + if action: + print("action: {}".format(action)) print("[{}] Shall we execute that snippet above?".format(i)) command = raw_input() if command == "": @@ -125,8 +148,17 @@ while True: if method == "bash": data += "\n" subprocess.check_call(["tmux", "send-keys", "{}".format(data)]) - if not wait_for_success(): - print("WARNING /!\ Command timed out.") + result = wait_for_success(wait_for=wait_for) + if result is True: + if action: + subprocess.check_call(["tmux", "send-keys", "{}".format(action)]) + wait_for_success() + # Unset wait_for and action so they don't carry over to the next loop. + wait_for, action = "", "" + elif result is False: + logging.warning("Last command failed!") + else: + logging.warning("Last command timed out!") else: print "DO NOT KNOW HOW TO HANDLE {} {!r}".format(method, data) i += 1 diff --git a/docs/sampleapp.md b/docs/sampleapp.md index aa6fe9d3..2c4b0274 100644 --- a/docs/sampleapp.md +++ b/docs/sampleapp.md @@ -135,6 +135,17 @@ Without further ado, let's start our application. cd ~/orchestration-workshop/dockercoins ``` + + - Use Compose to build and run all containers: ```bash docker-compose up @@ -160,17 +171,6 @@ and displays aggregated logs. - Stop the application by hitting `^C` - - ] - `^C` stops all containers by sending them the `TERM` signal @@ -215,17 +215,22 @@ class: extra-details docker-compose logs ``` + + - Stream container logs, starting at the last 10 lines for each container: ```bash docker-compose logs --tail 10 --follow ``` - - ] Tip: use `^S` and `^Q` to pause/resume log output. @@ -319,22 +324,29 @@ class: extra-details - run `top` to see CPU and memory usage (you should see idle cycles) - run `vmstat 1` to see I/O usage (si/so/bi/bo)
(the 4 numbers should be almost zero, except `bo` for logging) ] diff --git a/prepare-vms/workshopctl b/prepare-vms/workshopctl index c8b26861..26626749 100755 --- a/prepare-vms/workshopctl +++ b/prepare-vms/workshopctl @@ -22,7 +22,10 @@ DEPENDENCIES=" jq pssh wkhtmltopdf + jinja2 + pdfkit man + coloredlogs " ENVVARS="