-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ian Campbell <[email protected]>
- Loading branch information
Ian Campbell
committed
Dec 11, 2017
1 parent
9740eec
commit 6166887
Showing
3 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |