David Caro has uploaded a new change for review. Change subject: Added standard mock runner ......................................................................
Added standard mock runner It's a temporary script I wrote to help me debug the standard build scripts locally, use at your own risk Change-Id: Idbe80f0001affb0d16cb1db680f8f02283824cec Signed-off-by: David Caro <dcaro...@redhat.com> --- A mock_configs/mock_runner.sh 1 file changed, 342 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/93/40393/1 diff --git a/mock_configs/mock_runner.sh b/mock_configs/mock_runner.sh new file mode 100755 index 0000000..5d2b41c --- /dev/null +++ b/mock_configs/mock_runner.sh @@ -0,0 +1,342 @@ +#!/usr/bin/env bash + +MOCKS=( + el6:epel-6-x86_64 + el7:epel-7-x86_64 + fc19:fedora-19-x86_64 + fc20:fedora-20-x86_64 + fc21:fedora-21-x86_64 + fc22:fedora-22-x86_64 +) +SCRIPTS=( + automation/check-patch.sh + automation/check-merged.sh + automation/build-artifacts.sh +) +RUN_SHELL="false" +REBUILD="false" +MOCK_CONF_DIR="/etc/mock" +MOUNT_POINT="/tmp/run" + + +help() { + cat <<EOH + Usage: $0 [options] [mock_env [mock_env [...]]] + + Will run the automation/* scripts on mock environments, by default, it will + run check-patch, check-merged and build-artifacts in that order, on the + mock environments: ${MOCKS[@]} + + A mock environment must be passed as a ':' separated tuple of: + ID:MOCK_CONF + + Where the ID is the name used for it on the requirements file (usually in + the style fc19, el6 or similar) and MOCK_CONF is the mock configuration + name as passed to the mock -r option (usually, the configuration name + without extension, for example fedora-22-x86_64) + + Options: + -h|--help + Show this help + + -v|--verbose + Verbose + + -s|--shell chroot + Prepare the given chroot and start an interactive session + + -p|--patch-only + Prepare chroot for the check-patch script only + + -m|--merge-only + Prepare chroot for the check-merged script only + + -r|--rebuild + Clean the chroot prior to initializing, just in case + + Parameters: + mock_env + Name of the mock chroot to use, if none passed all of the defaults + will be used: ${MOCKS[@]} +EOH + return 0 +} + + +prepare_chroot() { + local chroot="${1?}" + local packages_file="${2?}" + local base_conf \ + tmp_conf + + base_conf="/etc/mock/$chroot.cfg" + if ! [[ -e "$baseconf" ]]; then + echo "Unable to find base mock conf $base_conf" + return 1 + fi + + tmp_conf="mocker-$conf.cfg" + cat >"$tmp_conf" <<EOC +import os + +config_opts["plugin_conf"]["bind_mount_enable"]='True' +config_opts["plugin_conf"]["bind_mount_opts"]["dirs"]=[[os.path.realpath(os.curdir), u'/tmp/run']] +EOC + cat "$base_conf" >> "$tmp_conf" + + init_chroot "$base_conf" + install_packages "$MOCK_CONF_DIR/$base_conf" "$packages_file" + return 0 +} + + +gen_mock_config() { + local chroot="${1?}" + local base_conf \ + tmp_conf + base_conf="/etc/mock/$chroot.cfg" + if ! [[ -e "$base_conf" ]]; then + echo "Unable to find base mock conf $base_conf" + return 1 + fi + + tmp_conf="mocker-${chroot}.cfg" + cat >"$tmp_conf" <<EOC +import os + +config_opts["plugin_conf"]["bind_mount_enable"]='True' +config_opts["plugin_conf"]["bind_mount_opts"]["dirs"]=[[os.path.realpath(os.curdir), u'$MOUNT_POINT']] +EOC + cat "$base_conf" >> "$tmp_conf" + echo "${tmp_conf%.*}" + return 0 +} + + +install_packages() { + local conf_file="${1?}" + local packages=("${@:2}") + local configdir="${conf_file%/*}" + local chroot="${conf_file##*/}" + mock \ + --configdir="$configdir" \ + --root="$chroot" \ + --install "${packages[@]}" + return $? +} + + +init_chroot() { + local chroot="${1?}" + mock \ + --configdir="$MOCK_CONF_DIR" \ + --root="$chroot" \ + --init + return $? +} + + +clean_chroot() { + local chroot="${1?}" + mock \ + --configdir="$MOCK_CONF_DIR" \ + --root="$chroot" \ + --clean + return $? +} + + +get_packages() { + local script="${1?}" + local distro_suffix="${2?}" + local packages_file \ + pfile + + packages_file="${script%.sh}.req" + found="false" + for pfile in "$packages_file" "${packages_file}.$distro_suffix"; do + if ! [[ -f "$pfile" ]]; then + continue + fi + found="true" + break + done + if [[ "$found" == "false" ]]; then + echo "ERROR: Unable to find package requirements file" \ + "$packages_file or ${packages_file}.$distro_id" + return 1 + fi + grep -v -e '^\#' "$pfile" \ + | grep -v -e '^\s*$' + return 0 +} + +run_shell() { + local mock_env="${1?}" + local script="${2?}" + local rebuild="${3:-false}" + local distro_id \ + mock_conf \ + packages_file \ + found \ + res + + mock_conf="${mock_env#*:}" + distro_id="${mock_env%:*}" + if [[ -z "$distro_id" ]] || [[ -z "$mock_conf" ]]; then + echo "ERROR: invalid mock environment passed: ${MOCKS[0]}" + return 1 + fi + + packages=($(get_packages "$script" "$distro_id")) + res=$? + if [[ "$res" != "0" ]]; then + return $res + fi + + if [[ "$rebuild" == "true" ]]; then + clean_chroot "$mock_conf" + fi + init_chroot "$mock_conf" + install_packages "$MOCK_CONF_DIR/$mock_conf" "${packages[@]}" + mock_conf="$(gen_mock_config "$mock_conf")" + /usr/bin/mock \ + --configdir="$PWD" \ + --root="$mock_conf" \ + --shell + return $? +} + + +run_script() { + local conf_file="${1?}" + local script="${2?}" + local chroot \ + configdir + configdir="${conf_file%/*}" + chroot="${conf_file##*/}" + /usr/bin/mock \ + --configdir="$configdir" \ + --root="$chroot" \ + --no-clean \ + --shell <<EOS + export HOME=$MOUNT_POINT + cd + chmod +x $script + ./$script +EOS + return $? +} + + +run_scripts() { + local mock_env="${1?}" + local rebuild="${2?}" + local scripts=("${@:3}") + local distro_id \ + mock_conf \ + packages_file \ + packages \ + script \ + res + + mock_conf="${mock_env#*:}" + distro_id="${mock_env%:*}" + if [[ -z "$distro_id" ]] || [[ -z "$mock_conf" ]]; then + echo "ERROR: invalid mock environment passed: ${MOCKS[0]}" + return 1 + fi + + if [[ "$rebuild" == "true" ]]; then + clean_chroot "$mock_conf" + fi + init_chroot "$mock_conf" + res="$?" + if [[ "$res" != "0" ]]; then + return $res + fi + mock_conf="$(gen_mock_config "$mock_conf")" + for script in "${scripts[@]}"; do + packages=($(get_packages "$script" "$distro_id")) + res=$? + if [[ "$res" != "0" ]]; then + return $res + fi + + install_packages "$PWD/$mock_conf" "${packages[@]}" + run_script "$PWD/$mock_conf" "$script" + res=$? + if [[ "$res" != "0" ]]; then + return $res + fi + done + return 0 +} + + + +if ! [[ "$0" =~ ^.*/bash$ ]]; then + + # Parse options + args="$(getopt \ + -o s:pmvhr \ + -l "shell:,patch-only,merged-only,verbose,help,rebuild" \ + -n "$0" -- "$@" \ + )" + #Bad arguments + if [[ $? -ne 0 ]]; then + help + exit 1 + fi + eval set -- "$args"; + while true; do + case "$1" in + -h|--help) + help + exit 0 + ;; + -v|--verbose) + shift + set -x + ;; + -s|--shell) + MOCKS=("$2") + shift 2 + RUN_SHELL="true" + ;; + -p|--patch-only) + shift + SCRIPTS=( automation/check-patch.sh ) + ;; + -m|--merged-only) + shift + SCRIPTS=( automation/check-merged.sh ) + ;; + -r|--rebuild) + shift + REBUILD="true" + ;; + --) + # end of options + shift + break + ;; + esac + done + + if [[ "$RUN_SHELL" == "true" ]]; then + run_shell "${MOCKS[0]}" "${SCRIPTS[0]}" "$REBUILD" + exit $? + else + if [[ -n "$1" ]]; then + MOCKS=("$@") + fi + for mock_env in "${MOCKS[@]}"; do + run_scripts "$mock_env" "$REBUILD" "${SCRIPTS[@]}" + res="$?" + if [[ "$res" != "0" ]]; then + exit $res + fi + done + fi +fi -- To view, visit https://gerrit.ovirt.org/40393 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Idbe80f0001affb0d16cb1db680f8f02283824cec Gerrit-PatchSet: 1 Gerrit-Project: jenkins Gerrit-Branch: master Gerrit-Owner: David Caro <dcaro...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches