aboutsummaryrefslogtreecommitdiff
path: root/tests/vm-check.sh
blob: 9390acb26a7408e27d6b3e499ebcaf3894b2412e (about) (plain) (blame)
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
#!/bin/sh
set -eu

usage() {
	cat <<-'EOF'
		Usage:
		  vm-check.sh [-x] -t TYPE -H HOST -r REMOTE
		  vm-check.sh -h
	EOF
}

help() {
	cat <<-'EOF'


		Options:
		  -x            shutdown the VM before running checks
		  -t TYPE       the type of VM being tested
		  -H HOST       the name of the host to SSH into
		  -r REMOTE     the base address of the remote package-repository
		  -h, --help    show this message



		Run end-to-end tests of the package repository.
	EOF
}


for flag in "$@"; do
	case "$flag" in
		--)
			break
			;;
		--help)
			usage
			help
			exit
			;;
		*)
			;;
	esac
done

SHUTDOWN=false
while getopts 'xt:H:r:h' flag; do
	case "$flag" in
		x)
			SHUTDOWN=true
			;;
		t)
			TYPE="$OPTARG"
			;;
		H)
			HOST="$OPTARG"
			;;
		r)
			REMOTE="$OPTARG"
			;;
		h)
			usage
			help
			exit
			;;
		*)
			usage >&2
			exit 2
			;;
	esac
done
shift $((OPTIND - 1))

eval "$(assert-arg -- "${TYPE:-}"   '-t TYPE')"
eval "$(assert-arg -- "${HOST:-}"   '-H HOST')"
eval "$(assert-arg -- "${REMOTE:-}" '-r REMOTE')"


SEP="$(color -c blacki ':')"
pre_guest() {
	sed "s|^|$(color -c green "$HOST")$SEP$(color -c yellow "$TYPE")$SEP |"
}

pre_host() {
	sed "s|^|$(color -c blueb "$0")$SEP |"
}

shutdown() {
	if [ "$SHUTDOWN" = true ]; then
		vm down "$HOST" 2>&1 | pre_host
	fi
}
trap shutdown EXIT

{
	if [ "$SHUTDOWN" = true ]; then
		vm down "$HOST"
	fi
	vm up "$HOST"
	untill -m5 -n5 ssh "$HOST" uptime
	scp tests/checks/"$TYPE".sh "$HOST":check.sh
} 2>&1 | pre_host
ssh "$HOST" sh check.sh "$REMOTE" 2>&1 | pre_guest