David Caro has uploaded a new change for review. Change subject: Added scripts for 3.4 to latest upgrade job ......................................................................
Added scripts for 3.4 to latest upgrade job Change-Id: I869ec85c9990677c52ca61549fce4f50f2650f33 Signed-off-by: David Caro <[email protected]> --- A jobs/ovirt-engine_upgrade_stable_to_3.4/answer.file.otopi A jobs/ovirt-engine_upgrade_stable_to_3.4/build_engine_rpm.sh A jobs/ovirt-engine_upgrade_stable_to_3.4/cleanup.file.otopi A jobs/ovirt-engine_upgrade_stable_to_3.4/upgrade.sh 4 files changed, 570 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/89/25989/1 diff --git a/jobs/ovirt-engine_upgrade_stable_to_3.4/answer.file.otopi b/jobs/ovirt-engine_upgrade_stable_to_3.4/answer.file.otopi new file mode 100644 index 0000000..98dec54 --- /dev/null +++ b/jobs/ovirt-engine_upgrade_stable_to_3.4/answer.file.otopi @@ -0,0 +1,34 @@ +[environment:default] +OVESETUP_AIO/storageDomainDir=none:None +OVESETUP_AIO/configure=none:None +OVESETUP_AIO/rootPassword=none:None +OSETUP_RPMDISTRO/enableUpgrade=bool:True +OVESETUP_CONFIG/storageType=str:nfs +OVESETUP_CONFIG/isoDomainName=str:ISO_DOMAIN +OVESETUP_CONFIG/websocketProxyConfig=bool:True +OVESETUP_CONFIG/adminPassword=str:123456 +OVESETUP_CONFIG/applicationMode=str:both +OVESETUP_CONFIG/firewallManager=str:iptables +OVESETUP_CONFIG/isoDomainMountPoint=str:/var/lib/exports/iso +OVESETUP_CONFIG/fqdn=str:CHANGE_HOSTNAME +OVESETUP_CONFIG/macRangePool=str:00:1A:4A:16:98:92-00:1A:4A:16:98:A1 +OVESETUP_CONFIG/updateFirewall=bool:True +OVESETUP_PKI/organization=str:ovirt.org +OVESETUP_SYSTEM/redhatSupportProxyEnabled=bool:False +OVESETUP_SYSTEM/nfsConfigEnabled=bool:True +OVESETUP_SYSTEM/memCheckEnabled=bool:False +OVESETUP_APACHE/configureSsl=bool:True +OVESETUP_APACHE/configureRootRedirection=bool:True +OVESETUP_DIALOG/confirmSettings=bool:True +OVESETUP_DIALOG/engineStop=bool:True +OVESETUP_DIALOG/confirmUpgrade=bool:False +OVESETUP_DB/securedHostValidation=bool:False +OVESETUP_DB/secured=bool:False +OVESETUP_DB/database=str:engine +OVESETUP_DB/host=str:localhost +OVESETUP_DB/user=str:engine +OVESETUP_DB/password=str:123456 +OVESETUP_DB/port=int:5432 +OVESETUP_PROVISIONING/postgresProvisioningEnabled=bool:True +OVESETUP_CORE/engineStop=bool:True +OSETUP_RPMDISTRO/requireRollback=bool:False diff --git a/jobs/ovirt-engine_upgrade_stable_to_3.4/build_engine_rpm.sh b/jobs/ovirt-engine_upgrade_stable_to_3.4/build_engine_rpm.sh new file mode 100755 index 0000000..5e0b8e9 --- /dev/null +++ b/jobs/ovirt-engine_upgrade_stable_to_3.4/build_engine_rpm.sh @@ -0,0 +1,167 @@ +#!/bin/bash -xe + +## Copyright (C) 2014 Red Hat, Inc., Kiril Nesenko <[email protected]> +### This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +shopt -s nullglob + +help() +{ + rc="$1" + msg="$2" + cat << EOH + USAGE: + > $0 [-h] -s SRC_DIR -d DST_DIR [-x MVN_SETTINGS] + + PARAMETERS: + -s SRC_DIR + Directory containing the engine sources + + -d DST_DIR + Directory where the built rpms will be put + + OPTIONS + -h + Show this help and exit + + -x MVN_SETTINGS + File with the maven settings to use +EOH + if [[ -n $rc ]]; then + [[ -n $msg ]] && echo "$msg" + exit $rc + fi +} + + +get_release_suffix() +{ + local src_ent="${1?}" + local rel + ## check if we have the git directory as source entity for the release + if [[ -d "$src_ent"/.git ]]; then + psuhd "$src_ent" &>/dev/null + rel=".git$(git rev-parse --short HEAD)" + else + echo "Unable to detect release from $src_ent" + return 1 + fi + echo "$rel" + return 0 +} + + +create_tarball() +{ + local src_dir="${1?}" + local dst_dir="${2?}" + pushd "$src_dir" &>/dev/null + rm -f ovirt-engine-*.tar.gz + make dist &> "$dst_dir/make_dist.log" \ + || return 1 + [[ -d "$dst_dir" ]] || mkdir -p "$dst_dir" + tarball=(ovirt-engine-*.tar.gz) + [[ -z $tarball ]] || ! [[ -e $tarball ]] \ + && { + echo "No tarball created at $src_dir" >&2 + return 1 + } + mv "$tarball" "$dst_dir/" + echo "$dst_dir/$tarball" + return 0 +} + + +create_src_rpm() +{ + local tarball="${1?}" + local dst_dir="${2?}" + local workspace="${3:-$PWD}" + local MAVEN_OPTS="${MAVEN_OPTS}" + MAVEN_OPTS+=" -XX:MaxPermSize=1024m -Dgwt.compiler.localWorkers=1" + MAVEN_OPTS+=" -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp" + MAVEN_OPTS+=" -Duser.home=$workspace" + rm -f "$workspace"/ovirt-engine-*.src.rpm + env MAVEN_OPTS="$MAVEN_OPTS" \ + rpmbuild \ + -D "_srcrpmdir $workspace" \ + -D "_specdir $workspace" \ + -D "_sourcedir $workspace" \ + -D "_rpmdir $workspace" \ + -D "_builddir $workspace" \ + -ts "$tarball" \ + &> "$dst_dir"/src_rpmbuild.log \ + || return 1 + src_rpm=("$workspace/"ovirt-engine-*.src.rpm) + [[ -z $src_rpm ]] || ! [[ -e $src_rpm ]] \ + && { + echo "No src rpm created at $workspace" >&2 + return 1 + } + mv "$src_rpm" "$dst_dir"/ + echo "$dst_dir/${src_rpm##*/}" + return 0 +} + + +create_rpms() +{ + local src_rpm="${1?}" + local dst_dir="${2?}" + local release="${3?}" + local workspace="${4:-$PWD}" + local MAVEN_OPTS="${MAVEN_OPTS}" + MAVEN_OPTS+=" -XX:MaxPermSize=1024m -Dgwt.compiler.localWorkers=1" + MAVEN_OPTS+=" -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp" + MAVEN_OPTS+=" -Duser.home=$workspace" + env MAVEN_OPTS="$MAVEN_OPTS" \ + rpmbuild \ + -D "ovirt_build_minimal 1" \ + -D "release_suffix $release" \ + -D "ovirt_build_extra_flags -gs ${CI_MAVEN_SETTINGS}" \ + -D "_srcrpmdir $dst_dir" \ + -D "_specdir $dst_dir" \ + -D "_sourcedir $dst_dir" \ + -D "_rpmdir $dst_dir" \ + -D "_builddir $dst_dir" \ + --rebuild "$src_rpm" \ + &> "$dst_dir"/rpmbuild.log \ + || return 1 + return 0 +} + + + +###### MAIN +unset SRC_DIR DST_DIR MVN_SETTINGS +while getopts s:d:x:h option; do + case $option in + s) SRC_DIR="$OPTARG";; + d) DST_DIR="$OPTARG";; + x) export CI_MAVEN_SETTINGS="$OPTARG";; + h) help 0;; + *) help 1 "Unknown option $option";; + esac +done + +[[ -z $SRC_DIR ]] && help 1 "No -s parameter passed" +[[ -z $DST_DIR ]] && help 1 "No -d parameter passed" +[[ -e $SRC_DIR ]] || help 1 "The source dirr $SRC_DIR does not exist." +[[ -e $DST_DIR ]] || mkdir -p "$DST_DIR" + +tarball="$(create_tarball "$SRC_DIR" "$DST_DIR")" +src_rpm="$(create_src_rpm "$tarball" "$DST_DIR")" +release="$(get_release_suffix "$SRC_DIR")" +create_rpms "$src_rpm" "$DST_DIR" "$release" diff --git a/jobs/ovirt-engine_upgrade_stable_to_3.4/cleanup.file.otopi b/jobs/ovirt-engine_upgrade_stable_to_3.4/cleanup.file.otopi new file mode 100644 index 0000000..ebff85c --- /dev/null +++ b/jobs/ovirt-engine_upgrade_stable_to_3.4/cleanup.file.otopi @@ -0,0 +1,22 @@ +# action=cleanup +[environment:default] +OVESETUP_CORE/engineStop=bool:True +OVESETUP_CORE/remove=bool:True +OVESETUP_DB/database=str:engine +OVESETUP_DB/secured=bool:False +OVESETUP_DB/host=str:localhost +OVESETUP_DB/user=str:engine +OVESETUP_DB/securedHostValidation=bool:False +OVESETUP_DB/password=str:123456 +OVESETUP_DB/port=str:5432 +OVESETUP_SYSTEM/nfsConfigEnabled=bool:True +OVESETUP_CONFIG/isoDomainName=str:ISO_DOMAIN +OVESETUP_CONFIG/isoDomainMountPoint=str:/var/lib/exports/iso +OVESETUP_CONFIG/firewallManager=str:iptables +OVESETUP_CONFIG/fqdn=str:CHANGE_HOSTNAME +OVESETUP_APACHE/configureRootRedirection=bool:True +OVESETUP_APACHE/configureSsl=bool:True +OVESETUP_REMOVE/confirmUninstallGroups=bool:True +OVESETUP_REMOVE/removeAll=bool:True +OVESETUP_REMOVE/database=bool:True +OVESETUP_REMOVE/enabledFileGroups=str:,ca_pki,iso_domain,versionlock,ca_config,core,exportfs,ca_pki,exportfs,versionlock,core diff --git a/jobs/ovirt-engine_upgrade_stable_to_3.4/upgrade.sh b/jobs/ovirt-engine_upgrade_stable_to_3.4/upgrade.sh new file mode 100755 index 0000000..43e924a --- /dev/null +++ b/jobs/ovirt-engine_upgrade_stable_to_3.4/upgrade.sh @@ -0,0 +1,347 @@ +#!/bin/bash -xe + +## Copyright (C) 2014 Red Hat, Inc., Kiril Nesenko <[email protected]> +### This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. + +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. + +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +DISABLED_REPOS=() + + +## This is the last function executed always when the script ends +cleanup() +{ + local workspace="${1?}" + local cleanup_file="${1?}" + local rc=0 + rm -f /etc/yum.repos.d/upgrade_test.repo + if which engine-setup &>/dev/null; then + engine-cleanup --config-append="${cleanup_file}" \ + || { + rc=$? + echo "CLEANUP_FAILED" + } + fi + rm -f /root/.pgpass + enable_engine_repos + find /var/log/ovirt-engine \ + -iname "*.log" \ + -exec tar cvzf"$workspace/logs {}.tgz" {} \; + return $? +} + + +die() { + local m="${1}" + echo "FATAL: ${m}" + exit 1 +} + +usage() { + cat << __EOF__ + USAGE: + > ${0} [parameters] + + PARAMETERS: + --workspace=WORKSPACE + path to workspace + + --from-repo-url=FROM + repo to install the from engine + + --to-repo-url=TO + repo to engine you want to upgrade to + + --static-repo=STATIC + link to a static nightly repo + + --cleanup-file=CLEANUP_FILE + Answerfile to use when running cleanup + + --setup-file=SETUP_FILE + Answerfile to use when running setup +__EOF__ +} + +get_opts() { + while [[ -n "${1}" ]]; do + opt="$1" + val="${opt#*=}" + shift + case "${opt}" in + --workspace=*) + WORKSPACE="${val}" + ;; + --from-repo-url=*) + REPO_FROM="${val}" + ;; + --to-repo-url=*) + REPO_TO="${val}" + ;; + --static-repo=*) + STATIC_REPO="${val}" + ;; + --cleanup-file=*) + CLEANUP_FILE="${val}" + ;; + *) + usage + die "Wrong option" + ;; + esac + done +} + +configure() { + ANS_FILE="${WORKSPACE}"/jenkins/jobs/ovirt_engine_upgrade_params/answer.file.otopi +} + +init_postgres() { + local res=0 + if rpm -q postgresql-server; then + service postgresql stop + yum remove -y postgresql-server + fi + ## rm -rf does not complain if the file does not exist + rm -rf /var/lib/pgsql/data + yum -y install postgresql-server + postgresql-setup initdb || res=$(($res + $?)) + ## ugly fig for the tests to work + cat >/var/lib/pgsql/data/pg_hba.conf <<EOF +host all all 127.0.0.1/0 trust +host all all ::1/128 trust +local all all trust +EOF + cat /var/lib/pgsql/data/pg_hba.conf + service postgresql start || res=$(($res + $?)) + psql -h 127.0.0.1 postgres postgres \ + -c "CREATE USER engine WITH PASSWORD '123456';" \ + || res=$(($res + $?)) + psql -h 127.0.0.1 postgres postgres \ + -c "CREATE DATABASE engine;" \ + || res=$(($res + $?)) + psql -h 127.0.0.1 postgres postgres \ + -c "GRANT ALL PRIVILEGES ON DATABASE engine TO engine;" \ + || res=$(($res + $?)) + [[ "${res}" -ne 0 ]] && die "Failed to init postgres" +} + + +prepare_pgpass() { + cat << PGPASS > $HOME/.pgpass +localhost:5432:*:postgres:123456 +localhost:5432:*:engine:123456 +127.0.0.1:5432:*:engine:123456 +127.0.0.1:5432:*:postgres:123456 +PGPASS + chmod 600 $HOME/.pgpass +} + + +prepare_database() { + init_postgres || return 1 + prepare_pgpass || return 1 +} + + +pre_clean() { + local workspace="${1?}" + local cleanup_file="${2?}" + echo "----- Cleaning old rpms... ----" + sed -i "s/CHANGE_HOSTNAME/${HOSTNAME}/g" "${cleanup_file}" + # Clean engine rpms + if rpm -q ovirt-engine; then + engine-cleanup -u \ + || engine-cleanup --config-append="${cleanup_file}" + fi + yum -y remove ovirt-engine\* vdsm\* httpd mod_ssl || : + disable_engine_repos + echo "" > /etc/exports + rm -rf /etc/httpd/* + rm -f "${workspace}"/*log "${workspace}"/*txt + rm -rf /var/lib/exports/iso + rm -rf /var/log/ovirt-engine +} + + +## Ugly, but until we have a solution to the ovirt repo installation on the +## slaves, this it will have to do the job +disable_engine_repos() { + for repo in /etc/yum.repos.d/*; do + if grep -qi ovirt "${repo}"; then + sed -i 's/enabled=1/enabled=0/g' "${repo}" + DISABLED_REPOS+=("$repo") + fi + done +} + + +enable_engine_repos() { + for repo in "${DISABLED_REPOS[@]}"; do + sed -i 's/enabled=0/enabled=1/g' "${repo}" + done +} + + +configure_repos() { + local from_repo="${1?}" + local to_repo="${2?}" + local static_repo="${3}" + local os="$(facter operatingsystem)" + shopt -s nocasematch + case $os in + fedora) os="fc";; + centos) os="el";; + esac + if [[ "$from_repo" =~ ^http.*$ ]]; then + from_repo="${from_repo}/rpm/${os}\$releaseserver" + fi + if [[ "$to_repo" =~ ^http.*$ ]]; then + to_repo="${to_repo}/rpm/${os}\$releaseserver" + fi + if [[ "$static_repo" =~ ^http.*$ ]]; then + static_repo="${static_repo}/rpm/${os}\$releaseserver" + fi + ## using a static name makes easy to cleanup and enforce collisions + ## With this repo file, you just have to + ## yum install ovirt-engine && yum --enablerepo=upgrade_to ovirt-engine + cat << EOF > /etc/yum.repos.d/upgrade_test.repo +## Created by ${JOB_URL} +[upgrade_from] +name=Engine base repo for the upgrade +baseurl=${from_repo} +enabled=1 +gpgcheck=0 + +[upgrade_to] +name=Engine target repo for the upgrade +baseurl=${to_repo} +enabled=0 +gpgcheck=0 +EOF + if [[ -n "$static_repo" ]]; then + cat << EOF >> /etc/yum.repos.d/upgrade_test.repo + +[static_repo] +name=Engine base static repo for the upgrade +baseurl=${static_repo} +enabled=1 +gpgcheck=0 +EOF + fi +} + + +collect_iptables_rules() { + local dst_file="${1?}" + iptables-save > "$dst_file" +} + + +install_from_engine() { + local answer_file="${1?}" + # Installing from version + yum -y install ovirt-engine --enablerepo=upgrade_params + sed -i "s/CHANGE_HOSTNAME/$HOSTNAME/g" "${answer_file}" + echo "Installing engine" + engine-setup --config-append="${answer_file}" \ + || { + "########## SETUP_FAILED" + return 1 + } + return 0 +} + + +engine_upgrade() { + local answer_file="${1?}" + yum -y update ovirt-engine-setup + echo "Running upgrade stup" + engine-setup --config-append="${answer_file}" \ + || { + echo "############## UPGRADE_FAILED" + return 1 + } + return 0 +} + + +wait_for_engine() { + local status + local ok=false + ## give it 5 minutes + local counter=5 + local password="$(grep -i 'OVESETUP_DB/password' "${ANS_FILE}" \ + | awk -F':' '{print $NF}')" + while ! ok; do + status="$(curl --user "admin@internal:${password}" \ + -I \ + --insecure https://localhost/api \ + | head -n 1 | awk '{print $2}')" + if [ "${status}" -ne 200 ]; then + counter=$((counter - 1)) + if [[ $counter -eq 0 ]]; then + echo "########## ERROR WAITING FOR ENGINE TO START" + return 1 + fi + sleep 60 + fi + done + return 0 +} + + +setup_env() +{ + local workspace="${1?}" + local cleanup_file="${2?}" + local repo_from="${3?}" + local repo_to="${4?}" + local static_repo="${5}" + ## prepare the logs dir + [[ -d "$workspace/logs" ]] || mkdir -p "$workspace/logs" + ## Make sure no dirty env + pre_clean "$workspace" "$cleanup_file" + ## Prepare the database and permissions + prepare_database + configure_repos "$repo_from" "$repo_to" "$static_repo" + install_from_engine + collect_iptables_rules "$workspace/logs/iptables_before_upgrade.txt" + configure_repo "${repo_to}" + [[ -n "${static_repo}" ]] && configure_repo "${static_repo}" +} + + +run_upgrade() +{ + local workspace="${1?}" + local answer_file="${2?}" + engine_upgrade "$answer_file" + collect_iptables_rules "$workspace/logs/iptables_after_upgrade.txt" + wait_for_engine +} + + +### MAIN +unset WORKSPACE FROM TO STATIC_REPO CLEANUP_FILE +get_opts "${@}" +[ -n "${WORKSPACE}" ] || die "Please specify the workspace" +[ -n "${REPO_TO}" ] || die "Please specify the repository to update to" +[ -n "${REPO_FROM}" ] || die " Please specify the repository to upgrade from" +[ -n "${CLEANUP_FILE}" ] || die " Please specify a cleanup answer file" +### trap for the cleanup +trap "cleanup \"$WORKSPACE\" \"${CLEANUP_FILE}\"" EXIT +setup_env "$WORKSPACE" "$CLEANUP_FILE" "$REPO_FROM" "$STATIC_REPO" \ + || die "######### Failed to set up the environment for the tests." +run_upgrade "$WORKSPACE" "$ANSWER_FILE" || die "############ UPGRADE FAILED" +## the cleanup will run at the end, no need to run it twice -- To view, visit http://gerrit.ovirt.org/25989 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I869ec85c9990677c52ca61549fce4f50f2650f33 Gerrit-PatchSet: 1 Gerrit-Project: jenkins Gerrit-Branch: master Gerrit-Owner: David Caro <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
