From 3809391545359c94e74346dda80282047fe89c88 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 26 Jun 2017 11:48:13 +0100 Subject: [PATCH] test: ensure ctr works in getty container This is based on examples/getty.yml modified to drop console=tty0 from the command line since we will be capturing/logging only the serial so want everything to go there. Also updates the getty example to pickup the latest containerd and ca-certificates as used in the top level linuxkit.yml. Fix a typo in the containerd test too. Signed-off-by: Ian Campbell --- examples/getty.yml | 4 +- .../cases/040_packages/003_containerd/test.sh | 2 +- .../007_getty-containerd/test-ctr.yml | 22 +++++ .../007_getty-containerd/test.exp | 96 +++++++++++++++++++ .../040_packages/007_getty-containerd/test.sh | 24 +++++ 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 test/cases/040_packages/007_getty-containerd/test-ctr.yml create mode 100755 test/cases/040_packages/007_getty-containerd/test.exp create mode 100755 test/cases/040_packages/007_getty-containerd/test.sh diff --git a/examples/getty.yml b/examples/getty.yml index 20f2bc283..44313b7a6 100644 --- a/examples/getty.yml +++ b/examples/getty.yml @@ -4,8 +4,8 @@ kernel: init: - linuxkit/init:17693d233dd009b2a3a8d23673cb85969e1dce80 - linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f - - linuxkit/containerd:b1766e4c4c09f63ac4925a6e4612852a93f7e73b - - linuxkit/ca-certificates:eabc5a6e59f05aa91529d80e9a595b85b046f935 + - linuxkit/containerd:a33cdcf50b8107ffe14c92802c460fe7ada39acd + - linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d onboot: - name: sysctl image: "linuxkit/sysctl:3aa6bc663c2849ef239be7d941d3eaf3e6fcc018" diff --git a/test/cases/040_packages/003_containerd/test.sh b/test/cases/040_packages/003_containerd/test.sh index 12457326e..3e9729985 100644 --- a/test/cases/040_packages/003_containerd/test.sh +++ b/test/cases/040_packages/003_containerd/test.sh @@ -1,5 +1,5 @@ #!/bin/sh -# SUMMARY: Run contianerd test +# SUMMARY: Run containerd test # LABELS: # REPEAT: diff --git a/test/cases/040_packages/007_getty-containerd/test-ctr.yml b/test/cases/040_packages/007_getty-containerd/test-ctr.yml new file mode 100644 index 000000000..7ea29cdad --- /dev/null +++ b/test/cases/040_packages/007_getty-containerd/test-ctr.yml @@ -0,0 +1,22 @@ +kernel: + image: "linuxkit/kernel:4.9.x" + cmdline: "console=ttyS0 page_poison=1" +init: + - linuxkit/init:17693d233dd009b2a3a8d23673cb85969e1dce80 + - linuxkit/runc:3a4e6cbf15470f62501b019b55e1caac5ee7689f + - linuxkit/containerd:a33cdcf50b8107ffe14c92802c460fe7ada39acd + - linuxkit/ca-certificates:75cf419fb58770884c3464eb687ec8dfc704169d +onboot: + - name: dhcpcd + image: "linuxkit/dhcpcd:7d2b8aaaf20c24ad7d11a5ea2ea5b4a80dc966f1" + command: ["/sbin/dhcpcd", "--nobackground", "-f", "/dhcpcd.conf", "-1"] +services: + - name: getty + image: "linuxkit/getty:9f27c1272b6d128c9a09745e916f151d09cb0d27" +files: + - path: etc/getty.shadow + # sample sets password for root to "abcdefgh" (without quotes) + contents: 'root:$6$6tPd2uhHrecCEKug$8mKfcgfwguP7f.BLdZsT1Wz7WIIJOBY1oUFHzIv9/O71M2J0EPdtFqFGTxB1UK5ejqQxRFQ.ZSG9YXR0SNsc11:17322:0:::::' +trust: + org: + - linuxkit diff --git a/test/cases/040_packages/007_getty-containerd/test.exp b/test/cases/040_packages/007_getty-containerd/test.exp new file mode 100755 index 000000000..23ae34301 --- /dev/null +++ b/test/cases/040_packages/007_getty-containerd/test.exp @@ -0,0 +1,96 @@ +#!/usr/bin/env expect +spawn linuxkit run test-ctr +set pid [exp_pid] +set timeout 60 +set prompt ":~# " + +expect { + timeout { + puts "FAILED boot" + exec kill -9 $pid + exit 1 + } + "Welcome to LinuxKit" { + puts "SUCCESS boot" + } +} +expect { + timeout { + puts "FAILED login user" + exec kill -9 $pid + exit 1 + } + "ogin: " { + send "root\n" + } +} +expect { + timeout { + puts "FAILED login pass" + exec kill -9 $pid + exit 1 + } + "assword: " { + send "abcdefgh\n" + } +} + +expect { + timeout { + puts "FAILED dist pull" + exec kill -9 $pid + exit 1 + } + $prompt { + send "dist pull docker.io/library/redis:alpine\n" + } +} +expect { + timeout { + puts "FAILED dist pull" + exec kill -9 $pid + exit 1 + } + $prompt { + puts "SUCCESS dist pull" + send "ctr run -t docker.io/library/redis:alpine test\n" + } +} +expect { + timeout { + puts "FAILED ctr run" + exec kill -9 $pid + exit 1 + } + "The server is now ready to accept connections on port 6379" { + puts "SUCCESS ctr run" + # Ctrl-C + send "\003" + } +} +expect { + timeout { + puts "FAILED kill ctr" + exec kill -9 $pid + exit 1 + } + $prompt { + send "poweroff -f\n" + } +} +expect { + timeout { + puts "FAILED poweroff" + exec kill -9 $pid + exit 1 + } + "Power down" { + puts "SUCCESS poweroff" + } + eof { + puts "SUCCESS poweroff" + } +} +set waitval [wait -i $spawn_id] +set exval [lindex $waitval 3] +exit $exval diff --git a/test/cases/040_packages/007_getty-containerd/test.sh b/test/cases/040_packages/007_getty-containerd/test.sh new file mode 100755 index 000000000..adb317820 --- /dev/null +++ b/test/cases/040_packages/007_getty-containerd/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# SUMMARY: Check that ctr can run containers +# LABELS: +# REPEAT: + +set -e + +# Source libraries. Uncomment if needed/defined +#. "${RT_LIB}" +. "${RT_PROJECT_ROOT}/_lib/lib.sh" + +NAME=test-ctr + +clean_up() { + find . -iname "test-ctr*" -not -iname "*.yml" -exec rm -rf {} \; +} +trap clean_up EXIT + +moby build "${NAME}.yml" +[ -f "${NAME}-kernel" ] || exit 1 +[ -f "${NAME}-initrd.img" ] || exit 1 +[ -f "${NAME}-cmdline" ]|| exit 1 +./test.exp +exit 0