aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/repo-install-test.sh
blob: 6b14cf2ee44f2280e543e9cdf3a8babfaf94c046 (plain)
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
#!/bin/sh -ex
# Environment variables:
# * INTERACTIVE: set to 1 to keep an interactive shell open after the script ran (for debugging)
# * FEED: binary package feed (e.g. "latest", "nightly")
# * PROJ: OBS project namespace (e.g. "network:osmocom:latest")
# * PROJ_CONFLICT: Conflicting OBS project namespace (e.g. "network:osmocom:nightly")
# * KEEP_CACHE: set to 1 to keep downloaded binary packages (for development)
# * TESTS: which tests to run (all by default, see below for possible values)
. "$(dirname "$0")/common.sh"

DISTRO="$1"
DISTROS="
	centos8
	debian10
	debian11
"

check_usage() {
	local i
	for i in $DISTROS; do
		if [ "$DISTRO" = "$i" ]; then
			return
		fi
	done
	echo "usage: repo-install-test.sh DISTRO"
	echo "DISTRO: one of: $DISTROS"
	exit 1
}

check_usage
docker_images_require "$DISTRO-repo-install-test"

FEED="${FEED:-nightly}"
PROJ="${PROJ:-network:osmocom:$FEED}"
CONTAINER="$DISTRO-repo-install-test-$FEED"

if [ -z "$TESTS" ]; then
	TESTS="
		test_conflict
		install_repo_packages
		test_binaries
		services_check
	"
fi

if [ -z "$PROJ_CONFLICT" ]; then
	case "$FEED" in
		latest)
			PROJ_CONFLICT="network:osmocom:nightly"
			;;
		nightly)
			PROJ_CONFLICT="network:osmocom:latest"
			if [ "$DISTRO" = "centos8" ]; then
				# Doesn't have packages built for "latest" yet
				PROJ_CONFLICT="network:osmocom:next"
			fi
			;;
		next)
			PROJ_CONFLICT="network:osmocom:nightly"
			;;
	esac
fi

# Try to run "systemctl status" 10 times, kill the container on failure
check_if_systemd_is_running() {
	for i in $(seq 1 10); do
		sleep 1
		if docker exec "$CONTAINER" systemctl status; then
			return
		fi
	done

	echo "ERROR: systemd is not running properly."
	docker container kill "$CONTAINER"
	exit 1
}

# Kill already running container
if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER" 2> /dev/null)" = "true" ]; then
	docker container kill "$CONTAINER"
	sleep 1
fi

# Additional docker run arguments
args=""
if [ -n "$KEEP_CACHE" ]; then
	args="$args -e KEEP_CACHE=1"
	args="$args -v $OSMO_CI_DIR/_repo_install_test_cache/debian/apt:/var/cache/apt"
	args="$args -v $OSMO_CI_DIR/_repo_install_test_cache/centos/dnf:/var/cache/dnf"
fi

# Run the container
# * This does not output anything, for debugging add -it and remove &.
# * /run, /tmp, cgroups, SYS_ADMIN: needed for systemd
# * SYS_NICE: needed for changing CPUScheduling{Policy,Priority} (osmo-bts systemd service files)
docker run	--rm \
		-v "$OSMO_CI_DIR/scripts/repo-install-test:/repo-install-test:ro" \
		--name "$CONTAINER" \
		-e FEED="$FEED" \
		-e PROJ="$PROJ" \
		-e PROJ_CONFLICT="$PROJ_CONFLICT" \
		-e DISTRO="$DISTRO" \
		-e TESTS="$TESTS" \
		-e container=docker \
		--tmpfs /run \
		--tmpfs /run/lock \
		--tmpfs /tmp \
		-v /sys/fs/cgroup:/sys/fs/cgroup:ro \
		--cap-add SYS_ADMIN \
		--cap-add SYS_NICE \
		$args \
		"$USER/$DISTRO-repo-install-test" \
		/lib/systemd/systemd &
check_if_systemd_is_running

# Run the test script
ret=0
if ! docker exec "$CONTAINER" /repo-install-test/run-inside-docker.sh; then
	ret=1
fi

# Interactive shell
if [ -n "$INTERACTIVE" ]; then
	docker exec -it "$CONTAINER" bash || true
fi

docker container kill "$CONTAINER"

exit $ret