forked from oVirt/ovirt-system-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-ost-container.sh
executable file
·170 lines (135 loc) · 3.17 KB
/
run-ost-container.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
#!/bin/bash -ex
readonly cli=docker
usage () {
echo "
Usage:
${0##*/} [options]
This script runs an OST container and mounts the current directory
in the container.
Optional arguments:
-h, --help
Show this message and exit
--lago-data-dir PATH
A persistent data directory for lago
--container-version VERSION
lago-ost container image version
--name NAME
A name for the newly created container
--suite SUITE
A suite to run inside the contatiner
--list
List all running OST containers
--remove-all
Remove all running OST containers
"
}
run() {
local name="${1?}"
local container_version="${2:?}"
local lago_data_dir="${3:?}"
local subnet_dir && subnet_dir="$(mktemp -d)"
local container_image="lagoproject/lago-ovirt:${container_version}"
chmod 777 "$subnet_dir"
"$cli" run \
-d \
--rm \
-v "${lago_data_dir}":/var/lib/lago \
-v "${subnet_dir}":/var/lib/lago/subnets \
-v "${PWD}:${PWD}" \
--device "/dev/kvm:/dev/kvm:rw" \
-w "$PWD" \
--privileged \
--name "$name" \
"$container_image"
}
run_suite() {
local cid="${1:?}"
local suite="${2:?}"
_exec "$cid" ./run_suite.sh "$suite"
}
connect() {
local cid="${1:?}"
_exec "$cid" /bin/bash
}
_exec() {
local cid="${1:?}"
local tty_flag
shift
tty -s && tty_flag="t"
"$cli" exec "-i${tty_flag}" "$cid" "$@"
}
list() {
"$cli" ps -f label=com.github.lago-project.lago-ost-plugin.version "$@"
}
remove_all() {
local ids
ids=($(list --format '{{.ID}}'))
for id in "${ids[@]}"; do
"$cli" rm -f "$id"
done
}
main() {
local options name cid suite
local container_version="0.45.2"
local lago_data_dir="/var/lib/lago"
options=$( \
getopt \
-o h \
--long help,lago-data-dir:,container-version:,name: \
--long remove-all,list,suite: \
-n 'run-ost-container.sh' \
-- "$@" \
)
if [[ "$?" != "0" ]]; then
echo "Failed to parse command"
exit 1
fi
eval set -- "$options"
while true; do
case $1 in
--name)
name="$2"
shift 2
;;
--container-version)
container_version="$2"
shift 2
;;
--lago-data-dir)
lago_data_dir="$2"
shift 2
;;
--list)
list
exit "$?"
;;
--remove-all)
remove_all
exit "$?"
;;
--suite)
suite="$2"
shift 2
;;
-h|--help)
usage
exit 0
;;
--)
shift
break
;;
esac
done
cid="$(run \
"$name" \
"$container_version" \
"$lago_data_dir"
)"
if [[ "$suite" ]]; then
run_suite "$cid" "$suite"
else
connect "$cid"
fi
}
[[ "${BASH_SOURCE[0]}" == "$0" ]] && main "$@"