Skip to content

Commit ae5b40a

Browse files
authored
Merge pull request kata-containers#114 from jodh-intel/kata-manager-update
tests: Update kata-manager command
2 parents 8e577c1 + 43a2ea4 commit ae5b40a

File tree

4 files changed

+139
-65
lines changed

4 files changed

+139
-65
lines changed

.ci/lib.sh

-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,3 @@ run_static_checks()
2323
clone_tests_repo
2424
bash "$tests_repo_dir/.ci/static-checks.sh" "github.com/kata-containers/osbuilder"
2525
}
26-
27-
install_bats()
28-
{
29-
bash "$tests_repo_dir/.ci/install_bats.sh"
30-
}

.ci/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export GOPATH="${GOPATH:-/tmp/go}"
1212

1313
script_dir="$(dirname $(readlink -f $0))"
1414

15-
sudo -E PATH="$PATH" bats "${script_dir}/../tests/image_creation.bats"
15+
sudo -E PATH="$PATH" bash "${script_dir}/../tests/image_creation.sh"

.ci/setup.sh

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ bash "${cidir}/static-checks.sh"
1515
#Note: If add clearlinux as supported CI use a stateless os-release file
1616
source /etc/os-release
1717

18-
install_bats
19-
2018
if [ "$ID" == fedora ];then
2119
sudo -E dnf -y install automake yamllint coreutils moreutils
2220
elif [ "$ID" == centos ];then

tests/image_creation.bats renamed to tests/image_creation.sh

+138-57
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,75 @@
1-
#!/usr/bin/env bats
1+
#!/bin/bash
22
#
33
# Copyright (c) 2018 Intel Corporation
44
#
55
# SPDX-License-Identifier: Apache-2.0
66

7-
readonly rootfs_sh="$BATS_TEST_DIRNAME/../rootfs-builder/rootfs.sh"
8-
readonly image_builder_sh="$BATS_TEST_DIRNAME/../image-builder/image_builder.sh"
9-
readonly initrd_builder_sh="$BATS_TEST_DIRNAME/../initrd-builder/initrd_builder.sh"
7+
set -e
8+
9+
readonly script_dir="$(dirname $(readlink -f $0))"
10+
11+
readonly rootfs_sh="${script_dir}/../rootfs-builder/rootfs.sh"
12+
readonly image_builder_sh="${script_dir}/../image-builder/image_builder.sh"
13+
readonly initrd_builder_sh="${script_dir}/../initrd-builder/initrd_builder.sh"
1014
readonly tmp_dir=$(mktemp -t -d osbuilder-test.XXXXXXX)
1115
readonly tmp_rootfs="${tmp_dir}/rootfs-osbuilder"
1216
readonly images_dir="${tmp_dir}/images"
1317
readonly osbuilder_file="/var/lib/osbuilder/osbuilder.yaml"
1418
readonly docker_image="busybox"
1519
readonly docker_config_file="/etc/systemd/system/docker.service.d/kata-containers.conf"
1620
readonly tests_repo="github.com/kata-containers/tests"
17-
readonly tests_repo_dir="$BATS_TEST_DIRNAME/../../tests"
21+
readonly tests_repo_dir="${script_dir}/../../tests"
1822
readonly mgr="${tests_repo_dir}/cmd/kata-manager/kata-manager.sh"
1923
readonly RUNTIME=${RUNTIME:-kata-runtime}
2024

2125
# "docker build" does not work with a VM-based runtime
2226
readonly docker_build_runtime="runc"
2327

28+
exit_handler()
29+
{
30+
if [ "$?" -eq 0 ]
31+
then
32+
# Rootfs and images are owned by root
33+
sudo -E rm -rf "${tmp_rootfs}"
34+
sudo -E rm -rf "${images_dir}"
35+
36+
rm -rf "${tmp_dir}"
37+
38+
return
39+
fi
40+
41+
# The test failed so dump what we can
42+
43+
info "AGENT_INIT: '${AGENT_INIT}'"
44+
45+
info "images:"
46+
sudo -E ls -l "${images_dir}" >&2
47+
48+
info "rootfs:"
49+
sudo -E ls -l "${tmp_rootfs}" >&2
50+
51+
info "local runtime config:"
52+
cat /etc/kata-containers/configuration.toml >&2
53+
54+
info "main runtime config:"
55+
cat /usr/share/defaults/kata-containers/configuration.toml >&2
56+
57+
info "collect script output:"
58+
sudo -E kata-collect-data.sh >&2
59+
60+
info "processes:"
61+
sudo -E ps -efwww | egrep "docker|kata" >&2
62+
}
63+
64+
trap exit_handler EXIT ERR
65+
66+
die()
67+
{
68+
msg="$*"
69+
echo "ERROR: $msg" >&2
70+
exit 1
71+
}
72+
2473
info()
2574
{
2675
s="$*"
@@ -31,6 +80,8 @@ set_runtime()
3180
{
3281
local name="$1"
3382

83+
[ -z "$name" ] && die "need name"
84+
3485
# Travis doesn't support VT-x
3586
[ -n "$TRAVIS" ] && return
3687

@@ -42,6 +93,7 @@ set_runtime()
4293

4394
setup()
4495
{
96+
[ -z "$images_dir" ] && die "need images directory"
4597
mkdir -p "${images_dir}"
4698

4799
export USE_DOCKER=true
@@ -51,54 +103,21 @@ setup()
51103

52104
[ ! -d "${tests_repo_dir}" ] && git clone "https://${tests_repo}" "${tests_repo_dir}"
53105

54-
chronic $mgr install-packages
106+
chronic $mgr install-docker-system
55107
chronic $mgr enable-debug
56108

57109
# Ensure "docker build" works
58110
set_runtime "${docker_build_runtime}"
59111
}
60112

61-
teardown()
62-
{
63-
if [ "$BATS_ERROR_STATUS" -eq 0 ]
64-
then
65-
# Rootfs and images are owned by root
66-
sudo -E rm -rf "${tmp_rootfs}"
67-
sudo -E rm -rf "${images_dir}"
68-
69-
rm -rf "${tmp_dir}"
70-
71-
return
72-
fi
73-
74-
# The test failed so dump what we can
75-
76-
info "AGENT_INIT: '${AGENT_INIT}'"
77-
78-
info "images:"
79-
sudo -E ls -l "${images_dir}" >&2
80-
81-
info "rootfs:"
82-
sudo -E ls -l "${tmp_rootfs}" >&2
83-
84-
info "local runtime config:"
85-
cat /etc/kata-containers/configuration.toml >&2
86-
87-
info "main runtime config:"
88-
cat /usr/share/defaults/kata-containers/configuration.toml >&2
89-
90-
info "collect script output:"
91-
sudo -E kata-collect-data.sh >&2
92-
93-
info "processes:"
94-
sudo -E ps -efwww | egrep "docker|kata" >&2
95-
}
96-
97113
build_rootfs()
98114
{
99115
local distro="$1"
100116
local rootfs="$2"
101117

118+
[ -z "$distro" ] && die "need distro"
119+
[ -z "$rootfs" ] && die "need rootfs"
120+
102121
local full="${rootfs}${osbuilder_file}"
103122

104123
# clean up from any previous runs
@@ -118,6 +137,9 @@ build_image()
118137
local file="$1"
119138
local rootfs="$2"
120139

140+
[ -z "$file" ] && die "need file"
141+
[ -z "$rootfs" ] && die "need rootfs"
142+
121143
sudo -E ${image_builder_sh} -o "${file}" "${rootfs}"
122144

123145
info "built image file '$file' for rootfs '$rootfs':"
@@ -129,6 +151,9 @@ build_initrd()
129151
local file="$1"
130152
local rootfs="$2"
131153

154+
[ -z "$file" ] && die "need file"
155+
[ -z "$rootfs" ] && die "need rootfs"
156+
132157
sudo -E ${initrd_builder_sh} -o "${file}" "${rootfs}"
133158

134159
info "built initrd file '$file' for rootfs '$rootfs':"
@@ -156,6 +181,9 @@ install_image_create_container()
156181
{
157182
local file="$1"
158183

184+
[ -z "$file" ] && die "need file"
185+
[ ! -e "$file" ] && die "file does not exist: $file"
186+
159187
# Travis doesn't support VT-x
160188
[ -n "$TRAVIS" ] && return
161189

@@ -168,6 +196,9 @@ install_initrd_create_container()
168196
{
169197
local file="$1"
170198

199+
[ -z "$file" ] && die "need file"
200+
[ ! -e "$file" ] && die "file does not exist: $file"
201+
171202
# Travis doesn't support VT-x
172203
[ -n "$TRAVIS" ] && return
173204

@@ -182,6 +213,9 @@ handle_options()
182213
local type="$2"
183214
local options="$3"
184215

216+
[ -z "$distro" ] && die "need distro"
217+
[ -z "$type" ] && die "need type"
218+
185219
local opt
186220
local rootfs
187221

@@ -241,7 +275,9 @@ create_and_run()
241275
local image_options="$2"
242276
local initrd_options="$3"
243277

244-
[ -n "$distro" ]
278+
[ -z "$distro" ] && die "need distro"
279+
[ -z "$image_options" ] && die "need image options"
280+
[ -z "$initrd_options" ] && die "need initrd options"
245281

246282
local opt
247283

@@ -256,27 +292,72 @@ create_and_run()
256292
fi
257293
}
258294

259-
@test "Can create and run fedora image" {
260-
create_and_run fedora "service" "no"
295+
run_test()
296+
{
297+
local -r name="$1"
298+
local -r skip="$2"
299+
local -r distro="$3"
300+
local -r image_options="$4"
301+
local -r initrd_options="$5"
302+
303+
[ -z "$name" ] && die "need name"
304+
[ -z "$distro" ] && die "need distro"
305+
[ -z "$image_options" ] && die "need image options"
306+
[ -z "$initrd_options" ] && die "need initrd options"
307+
308+
[ -n "$skip" ] && info "Skipping test $name: $skip" && return
309+
310+
info "Running test: ${name}"
311+
312+
create_and_run "${distro}" "${image_options}" "${initrd_options}"
261313
}
262314

263-
@test "Can create and run clearlinux image" {
264-
create_and_run clearlinux "service" "no"
315+
test_fedora()
316+
{
317+
local -r name="Can create and run fedora image"
318+
run_test "${name}" "" "fedora" "service" "no"
265319
}
266320

267-
@test "Can create and run centos image" {
268-
create_and_run centos "service" "no"
321+
test_clearlinux()
322+
{
323+
local -r name="Can create and run clearlinux image"
324+
325+
run_test "${name}" "" "clearlinux" "service" "no"
269326
}
270327

271-
@test "Can create and run euleros image" {
272-
if [ "$TRAVIS" = true ]
273-
then
274-
skip "travis timeout, see: https://github.com/kata-containers/osbuilder/issues/46"
275-
fi
328+
test_centos()
329+
{
330+
local -r name="Can create and run centos image"
331+
run_test "${name}" "" "centos" "service" "no"
332+
}
333+
334+
test_euleros()
335+
{
336+
local -r name="Can create and run euleros image"
337+
338+
[ "$TRAVIS" = true ] && skip="travis timeout, see: https://github.com/kata-containers/osbuilder/issues/46"
339+
340+
run_test "${name}" "$skip" "euleros" "service" "no"
341+
}
276342

277-
create_and_run euleros "service" "no"
343+
test_alpine()
344+
{
345+
local -r name="Can create and run alpine image"
346+
run_test "${name}" "" "alpine" "no" "init"
278347
}
279348

280-
@test "Can create and run alpine image" {
281-
create_and_run alpine "no" "init"
349+
main()
350+
{
351+
setup
352+
353+
test_fedora
354+
test_clearlinux
355+
test_centos
356+
test_alpine
357+
358+
# Run last as EulerOS servers can be slow and we don't want to fail the
359+
# previous tests.
360+
test_euleros
282361
}
362+
363+
main "$@"

0 commit comments

Comments
 (0)