mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-02-14 17:49:59 +00:00
Very crude auto-test harness driving tmux
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@ prepare-vms/ips.pdf
|
||||
prepare-vms/settings.yaml
|
||||
prepare-vms/tags
|
||||
docs/*.yml.html
|
||||
autotest/nextstep
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
../www/htdocs/index.html
|
||||
@@ -136,6 +136,12 @@ We should see the following things:
|
||||
kubectl logs deploy/pingpong --tail 1 --follow
|
||||
```
|
||||
|
||||
<!--
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
-->
|
||||
|
||||
]
|
||||
|
||||
---
|
||||
@@ -174,6 +180,12 @@ We could! But the *deployment* would notice it right away, and scale back to the
|
||||
kubectl get pods -w
|
||||
```
|
||||
|
||||
<!--
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
-->
|
||||
|
||||
- Destroy a pod:
|
||||
```bash
|
||||
kubectl delete pod pingpong-yyyy
|
||||
|
||||
@@ -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)
|
||||
|
||||
<!--
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
-->
|
||||
|
||||
]
|
||||
|
||||
--
|
||||
|
||||
@@ -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
|
||||
|
||||
<!--
|
||||
```meta
|
||||
^D
|
||||
```keys
|
||||
exit
|
||||
```
|
||||
-->
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
<!--
|
||||
```meta
|
||||
^D
|
||||
```keys
|
||||
exit
|
||||
```
|
||||
-->
|
||||
|
||||
|
||||
@@ -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[
|
||||
|
||||
<!--
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
-->
|
||||
|
||||
- Cancel the deployment and wait for the dust to settle down:
|
||||
```bash
|
||||
kubectl rollout undo deploy worker
|
||||
|
||||
@@ -161,9 +161,14 @@ and displays aggregated logs.
|
||||
- Stop the application by hitting `^C`
|
||||
|
||||
<!--
|
||||
```meta
|
||||
```wait
|
||||
units of work done
|
||||
```
|
||||
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
|
||||
-->
|
||||
|
||||
]
|
||||
@@ -216,7 +221,7 @@ class: extra-details
|
||||
```
|
||||
|
||||
<!--
|
||||
```meta
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
-->
|
||||
@@ -362,13 +367,6 @@ We have available resources.
|
||||
|
||||
- Look at the impact on CPU load and memory usage
|
||||
|
||||
<!--
|
||||
```bash
|
||||
sleep 5
|
||||
killall docker-compose
|
||||
```
|
||||
-->
|
||||
|
||||
]
|
||||
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user