forked from matelakat/storage-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-sm.sh
executable file
·142 lines (102 loc) · 2.92 KB
/
check-sm.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
#!/bin/bash
set -e
function usage() {
cat >&2 << EOF
$0
Check a given sm repository
Usage:
$0 SM_SOURCES WORKSPACE
Where:
SM_SOURCES A directory containing the storage manager repository
https://github.com/xapi-project/sm
WORKSPACE A workspace to be used. For the initial run, just
create an empty directory, and specify the same later
Example:
git clone https://github.com/xapi-project/sm
git clone https://github.com/matelakat/sm-ci
mkdir workspace
sm-ci/check-sm.sh sm workspace/
EOF
exit 1
}
function assert_installed() {
if which $1; then
return
fi
cat >&2 << EOF
Error:
$1 was not found, please install it to your system.
EOF
exit 1
}
[ -z "$1" ] && usage
[ -z "$2" ] && usage
set -eux
PATH_TO_SM="$1"
WORKDIR="$2"
# check dependencies
assert_installed fakeroot
assert_installed fakechroot
assert_installed debootstrap
THISFILE=$(readlink -f $0)
THISDIR=$(dirname $THISFILE)
. "$THISDIR/ci_lib.sh"
function install_sm_prereqs() {
local sm_tarball
local chroot_dir
sm_tarball="$1"
chroot_dir="$2"
chroot_dir="$(readlink -f $chroot_dir)"
local chroot_path
chroot_path="$chroot_dir/$CHROOT_SUBDIR"
[ -e "$sm_tarball" ]
[ -d "$chroot_path" ]
cp "$sm_tarball" "$chroot_path/source.tgz"
$(fakechroot_call) fakeroot chroot \
"$chroot_path" bash -c \
"rm -rf /storage-manager \
&& mkdir -p /storage-manager/sm \
&& cd /storage-manager/sm \
&& tar -xzf /source.tgz \
&& bash tests/install_prerequisites_for_python_unittests.sh"
}
function prepare_sm_venv() {
local sm_tarball
local chroot_dir
sm_tarball="$1"
chroot_dir="$2"
chroot_dir="$(readlink -f $chroot_dir)"
local chroot_path
chroot_path="$chroot_dir/$CHROOT_SUBDIR"
[ -e "$sm_tarball" ]
[ -d "$chroot_path" ]
cp "$sm_tarball" "$chroot_path/source.tgz"
$(fakechroot_call) fakeroot chroot \
"$chroot_path" bash -c \
"rm -rf /storage-manager \
&& mkdir -p /storage-manager/sm \
&& cd /storage-manager/sm \
&& tar -xzf /source.tgz \
&& bash tests/setup_env_for_python_unittests.sh"
}
function run_sm_tests() {
local sm_tarball
local chroot_dir
sm_tarball="$1"
chroot_dir="$2"
chroot_dir="$(readlink -f $chroot_dir)"
local chroot_path
chroot_path="$chroot_dir/$CHROOT_SUBDIR"
[ -e "$sm_tarball" ]
[ -d "$chroot_path" ]
cp "$sm_tarball" "$chroot_path/source.tgz"
$(fakechroot_call) fakeroot chroot \
"$chroot_path" bash -c \
"cd /storage-manager/sm \
&& rm -rf drivers tests \
&& tar -xzf /source.tgz \
&& bash tests/run_python_unittests.sh"
}
check "$PATH_TO_SM" "$WORKDIR" \
"install_sm_prereqs prepare_sm_venv" \
"run_sm_tests"