-
Notifications
You must be signed in to change notification settings - Fork 993
/
test_images.sh
executable file
·744 lines (606 loc) · 18.9 KB
/
test_images.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
#!/usr/bin/env bash
#
# Copyright (c) 2018 Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
[ -n "${DEBUG:-}" ] && set -o xtrace
readonly script_dir="$(dirname $(readlink -f $0))"
readonly script_name=${0##*/}
readonly project_dir="$(dirname ${script_dir})"
readonly tmp_dir=$(mktemp -t -d osbuilder-test.XXXXXXX)
readonly tmp_rootfs="${tmp_dir}/rootfs-osbuilder"
readonly images_dir="${tmp_dir}/images"
readonly osbuilder_file="/var/lib/osbuilder/osbuilder.yaml"
readonly docker_image="busybox"
readonly systemd_docker_config_file="/etc/systemd/system/docker.service.d/kata-containers.conf"
readonly sysconfig_docker_config_file="/etc/sysconfig/docker"
readonly tests_repo="github.com/kata-containers/tests"
readonly tests_repo_dir="${project_dir}/../tests"
readonly mgr="${tests_repo_dir}/cmd/kata-manager/kata-manager.sh"
readonly test_config=${script_dir}/test_config.sh
readonly rootfs_builder=${project_dir}/rootfs-builder/rootfs.sh
readonly DOCKER_RUNTIME=${DOCKER_RUNTIME:-runc}
readonly RUNTIME=${RUNTIME:-kata-runtime}
readonly MACHINE_TYPE=`uname -m`
readonly CI=${CI:-}
readonly KATA_HYPERVISOR="${KATA_HYPERVISOR:-}"
readonly KATA_DEV_MODE="${KATA_DEV_MODE:-}"
readonly ci_results_dir="/var/osbuilder/tests"
readonly dracut_dir=${project_dir}/dracut
build_images=1
build_initrds=1
typeset -a distrosSystemd distrosAgent
distrosSystemd=()
distrosAgent=()
# Hashes used to keep track of image sizes.
# - Key: name of distro.
# - Value: colon-separated roots and image sizes ("${rootfs_size}:${image_size}").
typeset -A built_images
typeset -A built_initrds
# If set, show the reason why a container using the built images/initrds could
# not be started. Needed only after all images/initrd built successfully
typeset -A showKataRunFailure=
source ${test_config}
source "${project_dir}/scripts/lib.sh"
usage()
{
cat <<EOF
Usage: $script_name [options] [command | <distro>]
Options:
-h | --help # Show usage.
--list # List all distros that can be tested.
--test-images-only # Only run images tests for the list of distros under test.
--test-initrds-only # Only run initrds tests for the list of distros under test.
Commands:
help : Show usage.
When <distro> is specified, tests are run only for the specified <distro>.
Otherwise, tests are run on all distros.
$(basename ${test_config}) includes a list of distros to exclude from testing,
depending on the detected test environment. However, when a <distro> is specified,
distro exclusion based on $(basename ${test_config}) is not enforced.
EOF
}
# Add an entry to the specified stats file
add_to_stats_file()
{
local statsfile="$1"
local name="$2"
local entry="$3"
local entry_type="$4"
local rootfs_size_bytes
local rootfs_size_mb
local image_size_bytes
local image_size_mb
rootfs_size_bytes=$(echo "$entry"|cut -d: -f1)
image_size_bytes=$(echo "$entry"|cut -d: -f2)
rootfs_size_mb=$(bc <<< "scale=2; ${rootfs_size_bytes} / 2^20")
image_size_mb=$(bc <<< "scale=2; ${image_size_bytes} / 2^20")
printf '%12.12s\t%10.10s\t%12.12s\t%10.10s\t%-8.8s\t%-20.20s\n' \
"${image_size_bytes}" \
"${image_size_mb}" \
"${rootfs_size_bytes}" \
"${rootfs_size_mb}" \
"${entry_type}" \
"${name}" >> "$statsfile"
}
# Show the sizes of all the generated initrds and images
show_stats()
{
local name
local sizes
local tmpfile=$(mktemp)
# images
for name in "${!built_images[@]}"
do
sizes=${built_images[$name]}
add_to_stats_file "$tmpfile" "$name" "$sizes" 'image'
done
# initrds
if [ "$KATA_HYPERVISOR" != "firecracker" ]; then
for name in "${!built_initrds[@]}"
do
sizes=${built_initrds[$name]}
add_to_stats_file "$tmpfile" "$name" "$sizes" 'initrd'
done
fi
info "Image and rootfs sizes (in bytes and MB), smallest image first:"
echo
printf '%12.12s\t%10.10s\t%12.12s\t%10.10s\t%-8.8s\t%-20.20s\n' \
"image-bytes" \
"image-MB" \
"rootfs-bytes" \
"rootfs-MB" \
"Type" \
"Name"
sort -k1,1n -k3,3n "$tmpfile"
rm -f "${tmpfile}"
}
# Run a kata-manager.sh command
run_mgr()
{
[ -n "${KATA_DEV_MODE:-}" ] && return
silent_run $mgr $*
}
exit_handler()
{
if [ "$?" -eq 0 ]
then
info "tests passed successfully - cleaning up"
# Rootfs and images are owned by root
sudo -E rm -rf "${tmp_rootfs}"
sudo -E rm -rf "${images_dir}"
rm -rf "${tmp_dir}"
# Restore the default image in config file
[ -n "${TRAVIS:-}" ] || run_mgr configure-image
return
fi
info "ERROR: test failed"
# The test failed so dump what we can
if [ -d "${tmp_rootfs}" ]; then
info "rootfs:"
sudo -E ls -l "${tmp_rootfs}" >&2
sudo -E rm -rf "${tmp_rootfs}"
else
info "no rootfs created"
# If no rootfs are created, no need to dump other info
return
fi
if [ -d "${images_dir}" ]; then
info "images:"
sudo -E ls -l "${images_dir}" >&2
sudo -E rm -rf "${images_dir}"
else
info "no images created"
# If no images are created, no need to dump other info
return
fi
if [ -z "${showKataRunFailure}" ]; then
# Restore the default image in config file
run_mgr configure-image
return
fi
info "local runtime config:"
cat /etc/kata-containers/configuration.toml >&2
info "main runtime config:"
cat /usr/share/defaults/kata-containers/configuration.toml >&2
info "collect script output:"
sudo -E kata-collect-data.sh >&2
info "processes:"
sudo -E ps -efwww | egrep "docker|kata" >&2
# Restore the default image in config file
run_mgr configure-image
}
die()
{
msg="$*"
echo "ERROR: $msg" >&2
exit 1
}
info()
{
s="$*"
echo -en "INFO: $s\n" >&2
}
debug()
{
[ -z "${TEST_DEBUG:-}" ] && return
s="$*"
echo -e "DBG: $s" >&2
}
# Run a command in silent mode using chronic.
# The command output is printed only if the command fails
silent_run()
{
typeset -a commandLine=("$@")
info "running: ${commandLine[@]}"
if [ -z "${DEBUG:-}" ]; then
chronic "${commandLine[@]}"
else
"${commandLine[@]}"
fi
}
set_runtime()
{
local name="$1"
[ -z "$name" ] && die "need name"
[ -n "${KATA_DEV_MODE}" ] && return
# Travis doesn't support VT-x
[ -n "${TRAVIS:-}" ] && return
if [ "$KATA_HYPERVISOR" != "firecracker" ]; then
if [ -f "$sysconfig_docker_config_file" ]; then
docker_config_file="$sysconfig_docker_config_file"
sed_script="s|^( *DOCKER_OPTS=.+--default-runtime[= ] *)[^ \"]+(.*\"$)|\1${name}\2|g"
else
docker_config_file="$systemd_docker_config_file"
sed_script="s/--default-runtime[= ][^ ]*/--default-runtime=${name}/g"
fi
sudo -E sed -i -E "$sed_script" "$docker_config_file"
sudo -E systemctl daemon-reload
sudo -E systemctl restart docker
fi
}
setup()
{
mkdir -p "${images_dir}"
if [ -n "$CI" ]; then
sudo -E rm -rf ${ci_results_dir}
sudo -E mkdir -p ${ci_results_dir}
fi
# Travis doesn't support VT-x
[ -n "${TRAVIS:-}" ] && return
[ ! -d "${tests_repo_dir}" ] && git clone "https://${tests_repo}" "${tests_repo_dir}"
if [ -z "${KATA_DEV_MODE}" ]; then
mkdir -p /etc/kata-containers/
sudo cp -a /usr/share/defaults/kata-containers/configuration.toml /etc/kata-containers/configuration.toml
else
info "Running with KATA_DEV_MODE set, skipping installation of docker and kata packages"
fi
run_mgr enable-debug
# "docker build" does not work with a VM-based runtime, and
# also does not accept a --runtime option, so our only
# option is to overwrite the system docker default runtime
set_runtime "${DOCKER_RUNTIME}"
}
# Fetches the distros test configuration from the distro-specific config.sh file.
# $1 : only fetch configuration for the distro with name $1. When not specified,
# fetch configuration for all distros.
get_distros_config()
{
local distro="$1"
local distrosList
local -A distroCfg=(\
[INIT_PROCESS]=\
[ARCH_EXCLUDE_LIST]=\
)
if [ -n "$distro" ]; then
distrosList=("$distro")
# When specifying a single distro name, skip does not apply
skipWhenTestingAll=()
else
distrosList=($(make list-distros))
fi
for d in ${distrosList[@]:-}; do
debug "Getting config for distro $d"
distroPattern="\<${d}\>"
if [[ "${skipWhenTestingAll[@]:-}" =~ $distroPattern ]]; then
info "Skipping distro $d as specified by $(basename ${test_config})"
continue
fi
tmpfile=$(mktemp /tmp/osbuilder-$d-config.XXX)
${rootfs_builder} -t $d > $tmpfile
# Get value of all keys in distroCfg
for k in ${!distroCfg[@]}; do
distroCfg[$k]="$(awk -v cfgKey=$k 'BEGIN{FS=":\t+"}{if ($1 == cfgKey) print $2}' $tmpfile)"
debug "distroCfg[$k]=${distroCfg[$k]}"
done
rm -f $tmpfile
machinePattern="\<${MACHINE_TYPE}\>"
if [[ "${distroCfg[ARCH_EXCLUDE_LIST]}" =~ $machinePattern ]]; then
info "Skipping distro $d on architecture $MACHINE_TYPE"
continue
fi
case "${distroCfg[INIT_PROCESS]}" in
systemd) distrosSystemd+=($d) ;;
kata-agent) distrosAgent+=($d) ;;
*) die "Invalid init process specified for distro $d: \"${distroCfg[INIT_PROCESS]}\"" ;;
esac
done
}
create_container()
{
# If KATA_DEV_MODE is set, we don't have any way to point kata-runtime
# at the image/initrd to boot, so there's nothing to do
[ -n "${KATA_DEV_MODE}" ] && return
out=$(mktemp)
local file="/proc/version"
# Create a container using the runtime under test which displays a
# file that is expected to exist.
docker run --rm -i --runtime "${RUNTIME}" "$docker_image" cat "${file}" > "$out"
info "contents of docker image ${docker_image} container file '${file}':"
cat "${out}" >&2
[ -s "$out" ]
rm -f "$out"
}
install_image_create_container()
{
local file="$1"
[ -z "$file" ] && die "need file"
[ ! -e "$file" ] && die "file does not exist: $file"
# Travis doesn't support VT-x
[ -n "${TRAVIS:-}" ] && return
showKataRunFailure=1
run_mgr reset-config
run_mgr enable-vsock
run_mgr configure-image "$file"
create_container
showKataRunFailure=
}
install_initrd_create_container()
{
local file="$1"
[ -z "$file" ] && die "need file"
[ ! -e "$file" ] && die "file does not exist: $file"
# Travis doesn't support VT-x
[ -n "${TRAVIS:-}" ] && return
showKataRunFailure=1
run_mgr reset-config
run_mgr enable-vsock
run_mgr configure-initrd "$file"
create_container
showKataRunFailure=
}
# Displays a list of distros which can be tested
list_distros()
{
tr " " "\n" <<< "${distrosSystemd[@]:-} ${distrosAgent[@]:-}" | sort
}
#
# Calls the `GNU make` utility with the set of passed arguments.
# Arguments can either be make targets or make variables assignments (in the form of VARIABLE=<value>)
#
call_make() {
targetType=$1
shift
makeVars=()
makeTargets=()
# Split args between make variable and targets
for t in $@; do
# RE to match a make variable assignment
pattern="^\w+\="
if [[ "$t" =~ $pattern ]]; then
makeVars+=("$t")
else
makeTargets+=($targetType-$t)
fi
done
# Set a default make target
[ "${#makeTargets[@]}" = "0" ] && makeTargets+=($targetType)
makeJobs=
if [ -z "$CI" ]; then
((makeJobs=$(nproc) / 2))
fi
# When calling make, do not use the silent_run wrapper, pass the
# OSBUILDER_USE_CHRONIC instead.
# In this way running make in parallel mode will, in case of failure, just
# show the print out of the single target failing.
makeVars+=(OSBUILDER_USE_CHRONIC=1)
info "Starting make with \n\
# of // jobs: ${makeJobs:-[unlimited]} \n\
targets: ${makeTargets[@]} \n\
variables: ${makeVars[@]}"
sudo -E make -j $makeJobs ${makeTargets[@]} ${makeVars[@]}
}
make_rootfs() {
call_make rootfs $@
}
make_image() {
call_make image $@
}
make_initrd() {
call_make initrd $@
}
get_rootfs_size() {
[ $# -ne 1 ] && die "get_rootfs_size: wrong number of arguments"
local rootfs_dir=$1
! [ -d "$rootfs_dir" ] && die "$rootfs_dir is not a valid rootfs path"
sudo -E du -sb "${rootfs_dir}" | awk '{print $1}'
}
show_rootfs_metadata() {
[ $# -ne 1 ] && die "show_rootfs_metadata: wrong number of arguments"
local rootfs_path=$1
local osbuilder_file_fullpath="${rootfs_path}/${osbuilder_file}"
yamllint "${osbuilder_file_fullpath}"
info "osbuilder metadata file for $d:"
cat "${osbuilder_file_fullpath}" >&2
}
# Create an image and/or initrd for the available distributions,
# then test each by configuring the runtime and creating a container.
#
# When passing the name of a distribution, tests are run against that
# distribution only.
#
# Parameters:
#
# 1: distro name.
#
test_distros()
{
local distro="$1"
get_distros_config "$distro"
local commonMakeVars=( \
USE_DOCKER=true \
DOCKER_RUNTIME="${DOCKER_RUNTIME}" \
ROOTFS_BUILD_DEST="$tmp_rootfs" \
IMAGES_BUILD_DEST="$images_dir" \
DEBUG=1 )
# If a distro was specified, filter out the distro list to only include that distro
if [ -n "$distro" ]; then
pattern="\<$distro\>"
if [[ "${distrosAgent[@]:-}" =~ $pattern ]]; then
distrosAgent=($distro)
distrosSystemd=()
elif [[ "${distrosSystemd[@]:-}" =~ $pattern ]]; then
distrosSystemd=($distro)
distrosAgent=()
build_initrds=
else
die "Not a valid distro: $distro"
fi
info "Running tests for distro: $distro"
else
info "Running tests for all distros"
# Graceful exit allowed for selected distros, but only when testing all distros
commonMakeVars+=(GRACEFUL_EXIT=1)
fi
# distro with systemd as init -> normal rootfs image
# distro with kata-agent as init -> normal rootfs image AND initrd image
# If user does not need rootfs images, then do not build systemd rootfses
[ -z "$build_images" ] && distrosSystemd=()
# Build systemd and agent rootfs with 2 separate jobs
bgJobs=()
if [ ${#distrosSystemd[@]} -gt 0 ]; then
info "building rootfses with systemd as init: ${distrosSystemd[@]}"
make_rootfs ${commonMakeVars[@]} "${distrosSystemd[@]}" &
bgJobs+=($!)
fi
if [ "$KATA_HYPERVISOR" != "firecracker" ]; then
if [ ${#distrosAgent[@]} -gt 0 ]; then
info "building all rootfses with kata-agent as init"
make_rootfs ${commonMakeVars[@]} AGENT_INIT=yes "${distrosAgent[@]}" &
bgJobs+=($!)
fi
fi
# Check for build failures (`wait` remembers up to CHILD_MAX bg processes exit status)
for j in ${bgJobs[@]}; do
if ! wait $j; then
info "Background rootfs build job failed:"
#find completed an uncompleted jobs checking for the rootfs marker
local marker=$(make print-ROOTFS_MARKER_SUFFIX)
[ -z "$marker" ] && die "Invalid rootfs marker"
typeset -a completed=($(find ${tmp_rootfs} -name ".*${marker}" -exec basename {} \; | sed -E "s/\.(.+)${marker}/\1/"))
for d in "${distrosSystemd[@]:-}" "${distrosAgent[@]:-}"; do
if [[ "${completed[@]}" =~ $d ]]; then
info "- $d : completed"
else
info "- $d : failed"
fi
done
die "rootfs build failed"
fi
done
# TODO: once support for rootfs images with kata-agent as init is in place,
# uncomment the following line
# for d in ${distrosSystemd[@]} ${distrosAgent[@]}; do
for d in ${distrosSystemd[@]:-}; do
local rootfs_path="${tmp_rootfs}/${d}_rootfs"
local image_path="${images_dir}/kata-containers-image-$d.img"
local rootfs_size=$(get_rootfs_size "$rootfs_path")
# Skip failed distros
if [ -e "${tmp_rootfs}/${d}_fail" ]; then
info "Building rootfs for ${d} failed, not creating an image"
[ -n "$CI" ] && sudo -E touch "${ci_results_dir}/${d}_fail"
continue
fi
show_rootfs_metadata "$rootfs_path"
info "Making rootfs image for ${d}"
make_image ${commonMakeVars[@]} $d
local image_size=$(stat -c "%s" "${image_path}")
built_images["${d}"]="${rootfs_size}:${image_size}"
info "Creating container for ${d}"
install_image_create_container $image_path
done
for d in ${distrosAgent[@]:-}; do
local rootfs_path="${tmp_rootfs}/${d}_rootfs"
local initrd_path="${images_dir}/kata-containers-initrd-$d.img"
local rootfs_size=$(get_rootfs_size "$rootfs_path")
# Skip failed distros
if [ -e "${tmp_rootfs}/${d}_fail" ]; then
info "Building rootfs for ${d} failed, not creating an initrd"
[ -n "$CI" ] && touch "${ci_results_dir}/${d}_fail"
continue
fi
if [ "$KATA_HYPERVISOR" != "firecracker" ]; then
info "Making initrd image for ${d}"
make_initrd ${commonMakeVars[@]} AGENT_INIT=yes $d
local initrd_size=$(stat -c "%s" "${initrd_path}")
built_initrds["${d}"]="${rootfs_size}:${initrd_size}"
info "Creating container for ${d}"
install_initrd_create_container $initrd_path
fi
done
show_stats
}
test_dracut()
{
local initrd_path="${images_dir}/kata-containers-initrd-dracut.img"
local image_path="${images_dir}/kata-containers-image-dracut.img"
local rootfs_path="${tmp_rootfs}/dracut_rootfs"
local overlay_path="${tmp_rootfs}/dracut_overlay"
detect_go_version ||
die "Could not detect the required Go version for AGENT_VERSION='${AGENT_VERSION:-master}'."
detect_rust_version ||
die "Could not detect the required rust version for AGENT_VERSION='${AGENT_VERSION:-master}'."
detect_musl_version ||
die "Could not detect the required musl version for AGENT_VERSION='${AGENT_VERSION:-master}'."
generate_dockerfile ${dracut_dir}
info "Creating container for dracut"
silent_run docker build -t dracut-test-osbuilder ${dracut_dir}
typeset -a dockerRunArgs=(\
--rm \
--runtime="${DOCKER_RUNTIME}" \
-v "${project_dir}":"${project_dir}" \
-v "${tmp_dir}":"${tmp_dir}" \
-v /etc/localtime:/etc/localtime:ro \
dracut-test-osbuilder \
)
typeset -a makeVars=(\
BUILD_METHOD=dracut \
TARGET_INITRD="${initrd_path}" \
TARGET_IMAGE=${image_path} \
TARGET_ROOTFS=${rootfs_path} \
DRACUT_OVERLAY_DIR="${overlay_path}" \
USE_DOCKER=1 \
DOCKER_RUNTIME="${DOCKER_RUNTIME}" \
)
info "Making image for dracut inside a container"
silent_run docker run ${dockerRunArgs[@]} make -C ${project_dir} ${makeVars[@]} rootfs
make_image ${makeVars[@]}
local image_size=$(stat -c "%s" "${image_path}")
local rootfs_size=$(get_rootfs_size "$rootfs_path")
built_images["dracut"]="${rootfs_size}:${image_size}"
info "Creating container for dracut"
install_image_create_container $image_path
if [ "$KATA_HYPERVISOR" != "firecracker" ]; then
info "Making initrd for dracut inside a container"
silent_run docker run ${dockerRunArgs[@]} make -C ${project_dir} ${makeVars[@]} AGENT_INIT=yes clean initrd
local initrd_size=$(stat -c "%s" "${initrd_path}")
built_initrds["dracut"]="${rootfs_size}:${initrd_size}"
install_initrd_create_container $initrd_path
fi
}
main()
{
local args=$(getopt \
-n "$script_name" \
-a \
--options="h" \
--longoptions="help distro: list test-images-only test-initrds-only" \
-- "$@")
eval set -- "$args"
[ $? -ne 0 ] && { usage >&2; exit 1; }
local distro=
while [ $# -gt 1 ]
do
case "$1" in
-h|--help) usage; exit 0 ;;
--list) list_distros; exit 0;;
--test-images-only)
build_initrds=
;;
--test-initrds-only)
build_images=
;;
--) shift; break ;;
esac
shift
done
# Consume getopt cruft
[ "$1" = "--" ] && shift
case "${1:-}" in
help) usage; exit 0;;
*) distro="${1:-}";;
esac
trap exit_handler EXIT ERR
setup
# Run only if distro is not dracut
[ "${distro:-}" != "dracut" ] && test_distros "$distro"
# Run if distro is empty or it is dracut
[ -z "$distro" ] || [ "$distro" = "dracut" ] && test_dracut
# We shouldn't really need a message like this but the CI can fail in
# mysterious ways so make it clear!
info "all tests finished successfully"
}
main "$@"