David Caro has uploaded a new change for review. Change subject: Adding proper database setup ......................................................................
Adding proper database setup Jobs were failing on database setup when trying to connect to it as the pg_hba file was being removed each time. Change-Id: I1d9daebdb557880a63d8eeca5c838d28d3808b1e Signed-off-by: David Caro <[email protected]> --- M jobs/ovirt_engine_upgrade_params/update_engine_params.sh 1 file changed, 126 insertions(+), 103 deletions(-) git pull ssh://gerrit.ovirt.org:29418/jenkins refs/changes/81/24781/1 diff --git a/jobs/ovirt_engine_upgrade_params/update_engine_params.sh b/jobs/ovirt_engine_upgrade_params/update_engine_params.sh index f27d3e6..18e1614 100644 --- a/jobs/ovirt_engine_upgrade_params/update_engine_params.sh +++ b/jobs/ovirt_engine_upgrade_params/update_engine_params.sh @@ -14,77 +14,100 @@ validate() { - if [[ -z "${WORKSPACE}" \ - || -z "${TO}" \ - || -z "${FROM}" ]]; then - echo "Please provide 3 parameters to the job" - exit 1 - fi + if [[ -z "${WORKSPACE}" \ + || -z "${TO}" \ + || -z "${FROM}" ]]; then + echo "Please provide 3 parameters to the job" + exit 1 + fi } init_postgres() { - local res=0 - if ! rpm -q postgresql-server; then - yum -y install postgresql-server - fi - - service postgresql stop - rm -rf /var/lib/pgsql/data - postgresql-setup initdb || res=$(($res + $?)) - service postgresql start || res=$(($res + $?)) - if [[ "${res}" -ne 0 ]]; then - echo "Failed to init postgres" - exit 1 - fi + local res=0 + if rpm -q postgresql-server; then + service postgresql stop + yum remove -y postgresql-server + fi + [[ -d /var/lib/pgsql/data ]]\ + && 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 + $?)) + if [[ "${res}" -ne 0 ]]; then + echo "Failed to init postgres" + exit 1 + fi } pre_clean() { - 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 - rm -rf /etc/httpd/* - rm -f "${WORKSPACE}"/*log "${WORKSPACE}"/*txt - echo "" > /etc/exports - rm -rf /var/lib/exports/iso + 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 + rm -rf /etc/httpd/* + rm -f "${WORKSPACE}"/*log "${WORKSPACE}"/*txt + echo "" > /etc/exports + rm -rf /var/lib/exports/iso } disable_engine_repos() { - sed -i 's/enabled=1/enabled=0/g' $(grep -li ovirt /etc/yum.repos.d/*) + for repo in /etc/yum.repos.d/*; do + grep -qi ovirt "$repo" \ + && sed -i 's/enabled=1/enabled=0/g' "$repo" + done } enable_engine_repos() { - sed -i 's/enabled=0/enabled=1/g' $(grep -li ovirt /etc/yum.repos.d/*) + for repo in /etc/yum.repos.d/*; do + grep -qi ovirt "$repo" \ + sed -i 's/enabled=0/enabled=1/g' "$repo" + done } configure_repo() { - local _release=$1 - local _os="" + local _release=$1 + local _os="" - if [[ "${OS}" == "fedora" ]]; then - _os="Fedora" - elif [[ "${OS}" == "centos" ]]; then - _os="EL" - else - echo "${_os} is not supported" - exit 1 - fi + if [[ "${OS}" == "fedora" ]]; then + _os="Fedora" + elif [[ "${OS}" == "centos" ]]; then + _os="EL" + else + echo "${_os} is not supported" + exit 1 + fi - cat << EOF > /etc/yum.repos.d/upgrade_params_${_release}.repo + cat << EOF > /etc/yum.repos.d/upgrade_params_${_release}.repo [ovirt-engine-${_release}] name=oVirt Engine ${_release} baseurl=http://ovirt.org/releases/${_release}/rpm/${_os}/\$releasever/ @@ -96,114 +119,114 @@ copy_log() { - LOG_NAME=$(ls -trll /var/log/ovirt-engine/setup | tail -n1 | grep -o "[^ ]*[.]log$") - cp -f /var/log/ovirt-engine/setup/"${LOG_NAME}" "${WORKSPACE}" + LOG_NAME=$(ls -trll /var/log/ovirt-engine/setup | tail -n1 | grep -o "[^ ]*[.]log$") + cp -f /var/log/ovirt-engine/setup/"${LOG_NAME}" "${WORKSPACE}" } collect_iptables_rules() { - _filename=$1 - iptables-save > "${WORKSPACE}"/"${_filename}".txt + _filename=$1 + iptables-save > "${WORKSPACE}"/"${_filename}".txt } install_from_engine() { - # Installing from version - yum -y install ovirt-engine --enablerepo=ovirt-engine-${FROM} + # Installing from version + yum -y install ovirt-engine --enablerepo=ovirt-engine-${FROM} - ENGINE_UPGRADE="engine-setup --config-append="${ANS_FILE}"" - ENGINE_CLEANUP="engine-cleanup --config-append="${CLEANUP_FILE}"" - ENGINE_SETUP=${ENGINE_UPGRADE} - sed -i "s/CHANGE_HOSTNAME/$HOSTNAME/g" "${ANS_FILE}" + ENGINE_UPGRADE="engine-setup --config-append="${ANS_FILE}"" + ENGINE_CLEANUP="engine-cleanup --config-append="${CLEANUP_FILE}"" + ENGINE_SETUP=${ENGINE_UPGRADE} + sed -i "s/CHANGE_HOSTNAME/$HOSTNAME/g" "${ANS_FILE}" - echo "Installing ${FROM} engine" - ${ENGINE_SETUP} - if [[ "${?}" -ne 0 ]]; then - echo "SETUP_FAILED" >> "${LOG}" - copy_log - exit 1 - fi - copy_log - collect_iptables_rules "before_upgrade" + echo "Installing ${FROM} engine" + ${ENGINE_SETUP} + if [[ "${?}" -ne 0 ]]; then + echo "SETUP_FAILED" >> "${LOG}" + copy_log + exit 1 + fi + copy_log + collect_iptables_rules "before_upgrade" } prepare_pgpass() { - cat << PGPASS > /root/.pgpass + cat << PGPASS > /root/.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 /root/.pgpass + chmod 600 /root/.pgpass } remove_pgpass() { - rm -f /root/.pgpass + rm -f /root/.pgpass } engine_upgrade() { - yum -y update ovirt-engine-setup - echo "Upgrading from $FROM to $TO" - ${ENGINE_UPGRADE} - if [[ "${?}" -ne 0 ]]; then - echo "UPGRADE_FAILED" >> ${LOG} - fi - copy_log - collect_iptables_rules "after_upgrade" - echo "" >> ${LOG} + yum -y update ovirt-engine-setup + echo "Upgrading from $FROM to $TO" + ${ENGINE_UPGRADE} + if [[ "${?}" -ne 0 ]]; then + echo "UPGRADE_FAILED" >> ${LOG} + fi + copy_log + collect_iptables_rules "after_upgrade" + echo "" >> ${LOG} } check_engine_status() { - sleep 60 - local _password=$(grep -i 'OVESETUP_DB/password' ${ANS_FILE} \ - | awk -F':' '{print $NF}') - local _status=$(curl --user "admin@internal:${_password}" \ - -I \ - --insecure https://localhost/api \ - | head -n 1 | awk '{print $2}') + sleep 60 + local _password=$(grep -i 'OVESETUP_DB/password' ${ANS_FILE} \ + | awk -F':' '{print $NF}') + local _status=$(curl --user "admin@internal:${_password}" \ + -I \ + --insecure https://localhost/api \ + | head -n 1 | awk '{print $2}') - if [[ "${_status}" -ne 200 ]]; then - echo "ENGINE_STATUS_ERROR" >> "${LOG}" - fi + if [[ "${_status}" -ne 200 ]]; then + echo "ENGINE_STATUS_ERROR" >> "${LOG}" + fi } post_clean() { - # Cleanup stage - rm -f /etc/yum.repos.d/upgrade_params_"${FROM}".repo \ - /etc/yum.repos.d/upgrade_params_"${TO}".repo - ${ENGINE_CLEANUP} || echo "CLEANUP_FAILED" >> "${LOG}" - copy_log + # Cleanup stage + rm -f /etc/yum.repos.d/upgrade_params_"${FROM}".repo \ + /etc/yum.repos.d/upgrade_params_"${TO}".repo + ${ENGINE_CLEANUP} || echo "CLEANUP_FAILED" >> "${LOG}" + copy_log } main() { - validate - pre_clean - init_postgres - disable_engine_repos - prepare_pgpass - configure_repo "${FROM}" - install_from_engine - configure_repo "${TO}" - engine_upgrade - check_engine_status - post_clean - enable_engine_repos - remove_pgpass + validate + pre_clean + init_postgres + disable_engine_repos + prepare_pgpass + configure_repo "${FROM}" + install_from_engine + configure_repo "${TO}" + engine_upgrade + check_engine_status + post_clean + enable_engine_repos + remove_pgpass } main -- To view, visit http://gerrit.ovirt.org/24781 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1d9daebdb557880a63d8eeca5c838d28d3808b1e 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
