-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathayer-dotbuild-mock
executable file
·101 lines (81 loc) · 2.58 KB
/
ayer-dotbuild-mock
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
#!/bin/bash -e
source /usr/lib/ayer/functions.sh || exit 1
ayer_init
# Usage: "$0" <project> <refspec> [<branch>] [<target>]
project=${1:?Project undefined.}
refspec=${2:?Refspec undefined.}
branch=${3:-$refspec}
target=${4:-test}
repo_ssh=$(gerrit_repo_ssh "$project")
script="./.build"
CONFIG_DIR="$HOME/.config/ayer"
#
# Create mock configuration
#
function clean_at_exit() {
rm -rf "$work_dir"
}
work_dir=$(mktemp -d -t ayer.XXXXXX)
trap clean_at_exit EXIT
cd "$work_dir"
mkdir mock_configdir
for file in site-defaults.cfg logging.ini; do
cp -p -t mock_configdir/ "$CONFIG_DIR/mock/$file"
done
ayer-mock-config "$CONFIG_DIR/mock.cfg.template" "./mock_configdir/ayer.cfg" \
"branch=$branch" \
"repo_url=$YUM_REPO_BASEURL_DEV/dev/$branch"
# yum compares modification time of configuration files with creation time
# of it's root cache, so we have to reset mtime of generated config
touch -r "$CONFIG_DIR/mock.cfg.template" "./mock_configdir/ayer.cfg"
# Runs mock with our params
a_mock () {
/usr/bin/mock \
--root ayer \
--configdir mock_configdir \
--verbose \
"$@"
}
# Prints out the list of packages needed in test environment
# Usage: packages_needed_to_test [specfile]
packages_needed_to_test () {
local specfile="$1"
{
# packages we'll need in almost every test environment:
echo python-nova
echo python-mox
# we'll also need most of packages rpm would depend on
[ -r "$specfile" ] && rpm --query --requires --specfile "$specfile"
} | awk '{ print $1; }' \
| sort -u \
| grep -v -e '^/bin/sh$' -e '^start-stop-daemon$'
}
# Get source
mkdir -p "$git_dir"
cd "$git_dir"
git_fetch_refspec "${project}.git" "$repo_ssh" "$refspec:$refspec"
cd "${project}.git"
tarball_dir="$work_dir/tarball"
mkdir -p "$tarball_dir"
git archive --format=tar "$refspec" | tar -xf - -C "$tarball_dir" 2>/dev/null
cd "$tarball_dir"
if [ ! -x "$script" ]; then
echo '#!/bin/bash
python setup.py test' > "$script"
chmod +x "$script"
fi
cd "$work_dir"
# Make new chroot and install packages to it
a_mock --scrub=yum-cache --clean
a_mock --init
packages_needed_to_test "$tarball_dir/"*.spec | while read; do
a_mock --install "$REPLY"
done
# Copy sources into chroot
internal_path="/builddir/$project"
a_mock --copyin "$tarball_dir" "$internal_path"
# To run .build as unprivileged user (which is cleaner) we need
# to set appropriate permissions
a_mock --chroot --cwd "$internal_path" "chown -R mockbuild:mockbuild ."
# At last, run what we wanted
a_mock --chroot --unpriv --cwd "$internal_path" "$script" "$target"