From 68e0c8fca7b1d3155f55eafc081609283a865abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Wed, 25 Oct 2017 11:40:37 +0200 Subject: [PATCH] Very crude auto-test harness driving tmux --- .gitignore | 1 + autotest/autotest.py | 95 +++++++++++++++----------------------------- autotest/index.html | 1 - docs/kubectlrun.md | 12 ++++++ docs/ourapponkube.md | 7 ++++ docs/prereqs-k8s.md | 16 +------- docs/prereqs.md | 16 +------- docs/rollout.md | 9 ++++- docs/sampleapp.md | 16 ++++---- 9 files changed, 72 insertions(+), 101 deletions(-) delete mode 120000 autotest/index.html diff --git a/.gitignore b/.gitignore index 5097a11c..40c39306 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ prepare-vms/ips.pdf prepare-vms/settings.yaml prepare-vms/tags docs/*.yml.html +autotest/nextstep diff --git a/autotest/autotest.py b/autotest/autotest.py index 8299836e..dbed5408 100755 --- a/autotest/autotest.py +++ b/autotest/autotest.py @@ -2,9 +2,8 @@ import os import re -import signal import subprocess -import time +import sys def print_snippet(snippet): print(78*'-') @@ -61,10 +60,9 @@ def ansi(code): return lambda s: "\x1b[{}m{}\x1b[0m".format(code, s) slides = [] -with open("index.html") as f: - content = f.read() - for slide in re.split("\n---?\n", content): - slides.append(Slide(slide)) +content = open(sys.argv[1]).read() +for slide in re.split("\n---?\n", content): + slides.append(Slide(slide)) is_editing_file = False placeholders = {} @@ -110,6 +108,9 @@ for slide in slides: elif highlight == "meta": print("^ "+content) snippet.actions.append((highlight, content)) + elif highlight == "keys": + print("K "+content) + snippet.actions.append((highlight, content)) else: print("! Unknown highlight {!r} on slide {}.".format(highlight, slide.number)) if placeholders: @@ -132,60 +133,30 @@ def strip_curly_braces(actions, in_braces=False): actions = strip_curly_braces(actions) -background = [] -cwd = os.path.expanduser("~") -env = {} -for current_action, next_action in zip(actions, actions[1:]+[("bash", "true")]): - if current_action[0] == "meta": - continue - print(ansi(7)(">>> {}".format(current_action[1]))) - time.sleep(1) - popen_options = dict(shell=True, cwd=cwd, stdin=subprocess.PIPE, preexec_fn=os.setpgrp) - # The follow hack allows to capture the environment variables set by `docker-machine env` - # FIXME: this doesn't handle `unset` for now - if any([ - "eval $(docker-machine env" in current_action[1], - "DOCKER_HOST" in current_action[1], - "COMPOSE_FILE" in current_action[1], - ]): - popen_options["stdout"] = subprocess.PIPE - current_action[1] += "\nenv" - proc = subprocess.Popen(current_action[1], **popen_options) - proc.cmd = current_action[1] - if next_action[0] == "meta": - print(">>> {}".format(next_action[1])) - time.sleep(3) - if next_action[1] == "^C": - os.killpg(proc.pid, signal.SIGINT) - proc.wait() - elif next_action[1] == "^Z": - # Let the process run - background.append(proc) - elif next_action[1] == "^D": - proc.communicate() - proc.wait() - else: - print("! Unknown meta action {} after snippet:".format(next_action[1])) - print_snippet(next_action[1]) - print(ansi(7)("<<< {}".format(current_action[1]))) - else: - proc.wait() - if "stdout" in popen_options: - stdout, stderr = proc.communicate() - for line in stdout.split('\n'): - if line.startswith("DOCKER_"): - variable, value = line.split('=', 1) - env[variable] = value - print("=== {}={}".format(variable, value)) - print(ansi(7)("<<< {} >>> {}".format(proc.returncode, current_action[1]))) - if proc.returncode != 0: - print("Got non-zero status code; aborting.") - break - if current_action[1].startswith("cd "): - cwd = os.path.expanduser(current_action[1][3:]) -for proc in background: - print("Terminating background process:") - print_snippet(proc.cmd) - proc.terminate() - proc.wait() +try: + i = int(open("nextstep").read()) +except Exception as e: + print("Could not read nextstep file ({}), initializing to 0.".format(e)) + i = 0 +while True: + with open("nextstep","w") as f: + f.write(str(i)) + typ, cmd = actions[i] + print_snippet(cmd) + print("i={} shall we execute the snippet above with {}?".format(i, typ)) + command = raw_input() + if command == "": + if typ in ["bash", "keys"]: + if typ=="keys" and cmd=="^C": + print("^C detected") + cmd="\x03" + subprocess.check_call(["tmux", "send-keys", "{}\n".format(cmd)]) + else: + print "DO NOT KNOW HOW TO HANDLE", typ, cmd + i += 1 + elif command.isdigit(): + i = int(command) + else: + i += 1 + # skip other "commands" diff --git a/autotest/index.html b/autotest/index.html deleted file mode 120000 index f8d31667..00000000 --- a/autotest/index.html +++ /dev/null @@ -1 +0,0 @@ -../www/htdocs/index.html \ No newline at end of file diff --git a/docs/kubectlrun.md b/docs/kubectlrun.md index 6e9071c6..bf26b011 100644 --- a/docs/kubectlrun.md +++ b/docs/kubectlrun.md @@ -136,6 +136,12 @@ We should see the following things: kubectl logs deploy/pingpong --tail 1 --follow ``` + + ] --- @@ -174,6 +180,12 @@ We could! But the *deployment* would notice it right away, and scale back to the kubectl get pods -w ``` + + - Destroy a pod: ```bash kubectl delete pod pingpong-yyyy diff --git a/docs/ourapponkube.md b/docs/ourapponkube.md index d7c0df80..8d3ba86f 100644 --- a/docs/ourapponkube.md +++ b/docs/ourapponkube.md @@ -184,6 +184,7 @@ The curl command should now output: - Build and push the images: ```bash + export REGISTRY docker-compose -f dockercoins.yml build docker-compose -f dockercoins.yml push ``` @@ -301,6 +302,12 @@ services: (Give it about 10 seconds to recover) + + ] -- diff --git a/docs/prereqs-k8s.md b/docs/prereqs-k8s.md index c0fd06dd..739730ec 100644 --- a/docs/prereqs-k8s.md +++ b/docs/prereqs-k8s.md @@ -92,18 +92,6 @@ class: in-person for N in $(seq 1 5); do ssh -o StrictHostKeyChecking=no node$N true done -for N in $(seq 1 5); do - (. - docker-machine rm -f node$N - ssh node$N "docker ps -aq | xargs -r docker rm -f" - ssh node$N sudo rm -f /etc/systemd/system/docker.service - ssh node$N sudo systemctl daemon-reload - echo Restarting node$N. - ssh node$N sudo systemctl restart docker - echo Restarted node$N. - ) & -done -wait ``` --> @@ -115,8 +103,8 @@ wait - Type `exit` or `^D` to come back to node1 diff --git a/docs/prereqs.md b/docs/prereqs.md index 3de5dc54..7fbc1a37 100644 --- a/docs/prereqs.md +++ b/docs/prereqs.md @@ -114,18 +114,6 @@ class: in-person for N in $(seq 1 5); do ssh -o StrictHostKeyChecking=no node$N true done -for N in $(seq 1 5); do - (. - docker-machine rm -f node$N - ssh node$N "docker ps -aq | xargs -r docker rm -f" - ssh node$N sudo rm -f /etc/systemd/system/docker.service - ssh node$N sudo systemctl daemon-reload - echo Restarting node$N. - ssh node$N sudo systemctl restart docker - echo Restarted node$N. - ) & -done -wait ``` --> @@ -137,8 +125,8 @@ wait - Type `exit` or `^D` to come back to node1 diff --git a/docs/rollout.md b/docs/rollout.md index 35a60fbf..cbcbd529 100644 --- a/docs/rollout.md +++ b/docs/rollout.md @@ -58,7 +58,8 @@ - Build a new tag and push it to the registry: ```bash - export REGISTRY=localhost:3xxxx TAG=v0.2 + #export REGISTRY=localhost:3xxxx + export TAG=v0.2 docker-compose -f dockercoins.yml build docker-compose -f dockercoins.yml push ``` @@ -126,6 +127,12 @@ Our rollout is stuck. However, the app is not dead (just 10% slower). .exercise[ + + - Cancel the deployment and wait for the dust to settle down: ```bash kubectl rollout undo deploy worker diff --git a/docs/sampleapp.md b/docs/sampleapp.md index 36c931c2..8a43c3c0 100644 --- a/docs/sampleapp.md +++ b/docs/sampleapp.md @@ -161,9 +161,14 @@ and displays aggregated logs. - Stop the application by hitting `^C` ] @@ -216,7 +221,7 @@ class: extra-details ``` @@ -362,13 +367,6 @@ We have available resources. - Look at the impact on CPU load and memory usage - - ] ---