Skip to content

Commit

Permalink
CI: Try booting something
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Campbell <[email protected]>
  • Loading branch information
Ian Campbell committed Dec 11, 2017
1 parent 9740eec commit 6166887
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 6 deletions.
74 changes: 69 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ image_build: &image_build
- image: debian:stretch
# image builds seem to need a bit more grunt (RAM) than usual. Possibly getting OOM killed, which https://github.com/moby/tool/pull/191 might help.
# NB: This will become a paid for feature at some point soon (with plenty of warning), so is not a long term solution.
# small 1.0 2GB
# medium (default) 2.0 4GB pass: fail:5
# medium+ 3.0 6GB pass: fail:2
# large 4.0 8GB pass:2 fail:
# xlarge 8.0 16GB
# small 1.0 2GB
# medium (default) 2.0 4GB pass: fail:5
# medium+ 3.0 6GB pass: fail:2
# large 4.0 8GB pass:2 fail:
# xlarge 8.0 16GB
resource_class: large
steps:
- run:
Expand Down Expand Up @@ -99,6 +99,26 @@ image_build: &image_build
root: /workspace
paths: images

image_boot: &image_boot
docker:
- image: debian:stretch
steps:
- run:
name: Configure $PATH
command: echo 'export PATH=/workspace/bin:$PATH' >> $BASH_ENV
- run:
name: Install packages
# ca-certificates are needed for attach_workspace (and git over https)
command: apt-get update && apt-get install -y ca-certificates curl expect git make openssh-client qemu strace
- attach_workspace:
at: /workspace
- checkout
- run:
name: Test boot
command: |
cp /workspace/images/kube-$KUBE_RUNTIME-$KUBE_NETWORK/kube-{master,node}.iso .
./test.exp
version: 2
jobs:
dependencies:
Expand Down Expand Up @@ -240,6 +260,30 @@ jobs:
- KUBE_RUNTIME: cri-containerd
- KUBE_NETWORK: bridge

boot-docker-weave:
<<: *image_boot
environment:
- KUBE_RUNTIME: docker
- KUBE_NETWORK: weave

#boot-docker-bridge:
# <<: *image_boot
# environment:
# - KUBE_RUNTIME: docker
# - KUBE_NETWORK: bridge

#boot-cri-containerd-weave:
# <<: *image_boot
# environment:
# - KUBE_RUNTIME: cri-containerd
# - KUBE_NETWORK: weave

boot-cri-containerd-bridge:
<<: *image_boot
environment:
- KUBE_RUNTIME: cri-containerd
- KUBE_NETWORK: bridge

push-pkgs-to-hub:
docker:
- image: debian:stretch
Expand Down Expand Up @@ -332,6 +376,22 @@ workflows:
- pkg-kubelet
- pkg-cri-containerd

- boot-docker-weave:
requires:
- image-docker-weave

#- boot-docker-bridge:
# requires:
# - image-docker-bridge

#- boot-cri-containerd-weave:
# requires:
# - image-cri-containerd-weave

- boot-cri-containerd-bridge:
requires:
- image-cri-containerd-bridge

- push-pkgs-to-hub:
# We want everything to have passed, which is a bit
# tedious. Some of these are already covered transitively,
Expand All @@ -346,3 +406,7 @@ workflows:
- image-docker-bridge
- image-cri-containerd-weave
- image-cri-containerd-bridge
- boot-docker-weave
#- boot-docker-bridge
#- boot-cri-containerd-weave
- boot-cri-containerd-bridge
2 changes: 1 addition & 1 deletion ssh_into_kubelet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sshopts="-o LogLevel=FATAL \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
-o IdentitiesOnly=yes \
$SSHOPTS"
${SSHOPTS:-}"

case $(uname -s) in
Linux)
Expand Down
124 changes: 124 additions & 0 deletions test.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/usr/bin/env expect

set con_prompt "(ns: getty) linuxkit-*:*# "
set ssh_prompt "linuxkit-*:*# "

proc kill args {
foreach what $args {
global $what
if [info exists $what] {
upvar #0 $what sid
set pid [exp_pid -i $sid]
puts "killing $what ($sid) = $pid"
exec /bin/kill $pid
close $sid
} else {
puts "not killing $what (not started)"
}
}
}

proc boot_linuxkit {} {
global lk_sid
# medium circle CI has 4G of RAM, use 3.5G for VM
spawn env {KUBE_RUN_ARGS=-publish 2222:22} KUBE_MEM=3584 KUBE_DISK=8G KUBE_CLEAR_STATE=y KUBE_MASTER_UNTAINT=y ./boot.sh
set lk_sid $spawn_id
puts "INFO lk ($lk_sid) is pid [exp_pid -i $lk_sid]"
}

proc ssh_into_kubelet {} {
global ssh_sid
spawn env {SSHOPTS=-p 2222 -o ConnectTimeout=5 -o LogLevel=DEBUG} ./ssh_into_kubelet.sh localhost
set ssh_sid $spawn_id
puts "INFO ssh ($ssh_sid) is pid [exp_pid -i $ssh_sid]"
}

proc await_prompt {sidvar promptvar step} {
upvar #0 $sidvar sid $promptvar prompt
expect -i $sid -timeout 60 \
$prompt {
puts "SUCCESS $step"
} timeout {
puts "FAIL $step (timeout)"
kill ssh_sid lk_sid
exit 1
} eof {
puts "FAIL $step (eof)"
kill ssh_sid lk_sid
exit 1
}
}

proc await_con_prompt {step} {
global lk_sid con_prompt
await_prompt lk_sid con_prompt $step
}

proc await_ssh_prompt {step} {
global ssh_sid ssh_prompt
await_prompt ssh_sid ssh_prompt $step
}

boot_linuxkit

await_con_prompt "boot"

send -i $lk_sid "ifconfig eth0\n"
await_con_prompt "ifconfig"

ssh_into_kubelet
# provide ssh_sid as an indirect, allowing ssh to be respawned, which
# changes the id, we need this in case ssh cannot immediately connect.
expect -i ssh_sid -timeout 180 \
$ssh_prompt {
puts "SUCCESS connected to ssh"
} "read: Connection reset by peer" {
# ssh happened too soon, wait a bit.
puts "RETRY ssh (conn reset)"
wait -i $ssh_sid
sleep 3
ssh_into_kubelet
exp_continue -continue_timer
} eof {
puts "RETRY ssh (eof)"
wait -i $ssh_sid
sleep 3
ssh_into_kubelet
exp_continue -continue_timer
} timeout {
puts "FAIL ssh (timeout)"
kill ssh_sid lk_sid
exit 1
}

puts "RUN kubeadm-init.sh"
send -i ssh_sid "kubeadm-init.sh\n"

expect -i $ssh_sid -timeout 180 \
"Your Kubernetes master has initialized successfully!" {
puts "SUCCESS cluster initialised!"
} timeout {
puts "FAIL kubeadm-init.sh (timeout)"
kill ssh_sid lk_sid
exit 1
} eof {
puts "FAIL kubeadm-init.sh (eof)"
kill ssh_sid lk_sid
exit 1
}

await_ssh_prompt "kubeadm-init.sh"

puts "RUN poweroff -f"
send -i $lk_sid "poweroff -f\n"

expect -i $lk_sid -timeout 60 \
"Power down" {
puts "SUCCESS poweroff"
} eof {
puts "SUCCESS poweroff"
} timeout {
puts "FAILED poweroff (timeout)"
kill ssh_sid
exit 1
}

0 comments on commit 6166887

Please sign in to comment.