| #!/bin/bash |
| # |
| # This script test the temporary repos created by |
| # create_temporary_repos.sh script. It install new packages |
| # in mock environment, check that the packages have been |
| # properly installed and run repoclosure on them. |
| # |
| |
| set -o pipefail |
| set -x |
| |
| source "$(dirname $0)/common_functions" |
| |
| if [ $# -ne 1 ] && [ $# -ne 2 ]; then |
| echo "Usage: $(basename $0) WORKING_DIR [LOCAL_INFO_FILE]" |
| exit 1 |
| fi |
| |
| FAILED=0 |
| JOB_PATH=$(realpath $1) |
| LOGS_PATH=$JOB_PATH/logs |
| REPOS_PATH=$JOB_PATH/repos |
| REPOS_PATH_FMT=$(echo $REPOS_PATH | sed 's/\//\\\//g') |
| CFG_DIR=/etc/mock |
| CREPOS_FILE=$REPOS_PATH/changed_repos.txt |
| if [ -n "$2" ]; then |
| INFO_FILE="-l $2" |
| else |
| INFO_FILE="" |
| fi |
| MASTER_RELEASE="$(rdopkg info $INFO_FILE | grep -e "in development phase" | awk '{print $1}')" |
| |
| if [ ! -f $CREPOS_FILE ]; then |
| log "ERROR" "File $CREPOS_FILE not found" |
| exit 1 |
| fi |
| |
| mkdir -p $LOGS_PATH |
| |
| # As logs of this job can be long, i'll create a summary message that will be |
| # shown at the end of the script |
| SUMMARY='' |
| |
| function generate_config() |
| { |
| # Generate mock config with temporary repos to test packages installation |
| local REPO=$1 |
| local RELEASE=$2 |
| local PHASE=$3 |
| |
| log "INFO" "Generating mock config for $REPO" |
| |
| sudo rm -f $CFG_DIR/$REPO.cfg |
| |
| if [[ "$REPO" == *"cloud8s"* ]]; then |
| sudo cp -f mock-config-c8s.cfg $CFG_DIR/$REPO.cfg |
| export DIST_VER=8 |
| export STREAM="s" |
| export STREAMPATH="-stream" |
| elif [[ "$REPO" == *"cloud9s"* ]]; then |
| sudo cp -f mock-config-c9s.cfg $CFG_DIR/$REPO.cfg |
| export DIST_VER=9 |
| export STREAM="s" |
| export STREAMPATH="-stream" |
| fi |
| |
| if [ $RELEASE != $MASTER_RELEASE ]; then |
| RDO_TRUNK_RELEASE=$RELEASE |
| else |
| RDO_TRUNK_RELEASE="master" |
| fi |
| |
| curl -s -L https://trunk.rdoproject.org/centos${DIST_VER}-${RDO_TRUNK_RELEASE}/current/delorean.repo | \ |
| sed "s/^\[/\[${RDO_TRUNK_RELEASE}-dlrn-/;\ |
| s/^enabled=.*/enabled=0/" | \ |
| sudo tee -a $CFG_DIR/$REPO.cfg 1> /dev/null |
| |
| echo '"""' | sudo tee -a $CFG_DIR/$REPO.cfg 1> /dev/null |
| sudo sed -i "s/RDO_RELEASE/$RELEASE/g" $CFG_DIR/$REPO.cfg |
| sudo sed -i "s/REPOS_PATH_FMT/$REPOS_PATH_FMT/g" $CFG_DIR/$REPO.cfg |
| sudo sed -i "s/RELEASE_TAG_NAME/$REPO/g" $CFG_DIR/$REPO.cfg |
| |
| DEPS_BASEURL="https://trunk.rdoproject.org/centos${DIST_VER}-$RDO_TRUNK_RELEASE/deps/latest" |
| BUILDREQS_BASEURL="https://trunk.rdoproject.org/centos${DIST_VER}-$RDO_TRUNK_RELEASE/build-deps/latest" |
| |
| sudo sed -i "s|DEPS_BASEURL|$DEPS_BASEURL|g" $CFG_DIR/$REPO.cfg |
| sudo sed -i "s|BUILDREQS_BASEURL|$BUILDREQS_BASEURL|g" $CFG_DIR/$REPO.cfg |
| |
| log "INFO" "Displaying content of $CFG_DIR/$REPO.cfg" |
| sudo cat $CFG_DIR/$REPO.cfg |
| } |
| |
| function install_temp_repo() |
| { |
| # Test new packages installation using mock and run repoclosure |
| local REPO=$1 |
| local RELEASE=$2 |
| local PHASE=$3 |
| local dlrn_repos |
| local ENABLED MOCK_CMD |
| |
| if [ $RELEASE != $MASTER_RELEASE ]; then |
| RDO_TRUNK_RELEASE=$RELEASE |
| else |
| RDO_TRUNK_RELEASE="master" |
| fi |
| |
| log "INFO" "Validating repo $REPO" |
| |
| MOCK_CMD="sudo mock --configdir $CFG_DIR -r $REPO" |
| $MOCK_CMD --clean |
| |
| if [ $? -ne 0 ]; then |
| cat /var/lib/mock/$REPO*/result/root.log |
| cp /var/lib/mock/$REPO*/result/root.log $LOGS_PATH/root-$RELEASE-$PHASE.log |
| log "ERROR" "Job failed in mock clean. Details for this error can be found on logserver under logs/root-$RELEASE-$PHASE.log" |
| return 1 |
| fi |
| |
| ENABLED="--enablerepo=temp-$REPO" |
| |
| if [ $PHASE = "testing" ];then |
| ENABLED="$ENABLED --enablerepo=$RELEASE-testing --enablerepo=$RDO_TRUNK_RELEASE-dlrn*" |
| # NOTE(jpena): For Rocky and newer, we need to add the release-testing-rdo repo |
| # to ensure the RDO base packages are also included |
| if [ $(echo $BRS_IN_TESTING | grep -c -w $RELEASE) -eq 0 ] && [ $RDO_TRUNK_RELEASE != "master" ] ; then |
| ENABLED="$ENABLED --enablerepo=$RELEASE-testing-rdo" |
| fi |
| elif [ $PHASE = "release" ];then |
| # Need not enable release repo for initial promotion of $MASTER_RELEASE |
| REPOMD_URL_MASTER=http://mirror.centos.org/centos/${DIST_VER}${STREAMPATH}/cloud/x86_64/openstack-${MASTER_RELEASE}/repodata/repomd.xml |
| if [[ "$REPO" == *"cloud9s"* ]]; then |
| REPOMD_URL_MASTER=http://mirror.stream.centos.org/SIGs/${DIST_VER}${STREAMPATH}/cloud/x86_64/openstack-${MASTER_RELEASE}/repodata/repomd.xml |
| fi |
| if [ $RDO_TRUNK_RELEASE = "master" ] && [ $(curl -s -o /dev/null -w "%{http_code}" ${REPOMD_URL_MASTER}) != 404 ]; then |
| ENABLED="$ENABLED --enablerepo=$RELEASE" |
| elif [ $RDO_TRUNK_RELEASE != "master" ]; then |
| ENABLED="$ENABLED --enablerepo=$RELEASE" |
| fi |
| elif [[ $PHASE =~ el${DIST_VER}.*-build ]];then |
| ENABLED="$ENABLED --enablerepo=$RELEASE-testing --enablerepo=$RELEASE-deps-build" |
| if [ $(grep -c $RELEASE-testing $CREPOS_FILE) -gt 0 ]; then |
| ENABLED="$ENABLED --enablerepo=temp-cloud${DIST_VER}${STREAM}-openstack-$RELEASE-testing" |
| fi |
| fi |
| |
| LIST=$(cat $REPOS_PATH/$REPO.content.txt | while read line; do basename -s .rpm $line; done | tr '\n' ' ') |
| |
| log "INFO" "Installing $LIST from repo $REPO" |
| |
| $MOCK_CMD --no-bootstrap-chroot $ENABLED -i $LIST |
| |
| if [ $? -ne 0 ]; then |
| cat /var/lib/mock/$REPO*/result/root.log |
| cp /var/lib/mock/$REPO*/result/root.log $LOGS_PATH/root-$RDO_TRUNK_RELEASE-$PHASE.log |
| log "ERROR" "Job failed in mock packages install. Details for this error can be found on logserver under logs/root-$RDO_TRUNK_RELEASE-$PHASE.log" |
| return 1 |
| fi |
| |
| $MOCK_CMD --chroot "rpm -q $LIST" |
| |
| if [ $? -ne 0 ]; then |
| log "ERROR" "Following packages are not installed" |
| grep -oP "package \K\w+.* (?=is not installed)" /var/lib/mock/$REPO*/result/root.log | uniq |
| cp /var/lib/mock/$REPO*/result/root.log $LOGS_PATH/root-$RDO_TRUNK_RELEASE-$PHASE.log |
| log "ERROR" "Job failed in packages check(rpm -q). Details for this error can be found on logserver under logs/root-$RDO_TRUNK_RELEASE-$PHASE.log" |
| return 1 |
| fi |
| |
| #repoclosure test |
| log "INFO" "Running repoclosure for repo $REPO" |
| |
| # set -x |
| if [[ $REPO == *"9s"* ]]; then |
| REPOCLOSURE="repoclosure -n --releasever 9 --arch x86_64 --arch noarch --repo baseos --repo appstream --repo crb" |
| else |
| REPOCLOSURE="repoclosure -n --releasever 8 --arch x86_64 --arch noarch --repo baseos --repo appstream --repo powertools" |
| fi |
| |
| CLOSUREOPTS=$(echo $ENABLED | sed 's/--enablerepo=/--repo /g') |
| |
| # Create a yum repos configuration to be used with repoclosure based on mock config |
| sed '1,/# repo/ d' $CFG_DIR/$REPO.cfg | sed '/^config_opts/d' | sed 's/"""//g' > $REPOS_PATH/$REPO.repo |
| dlrn_repos=$(grep "dlrn-*" $REPOS_PATH/$REPO.repo | sed 's/[][]//g' | sed 's/^/--repo /' | tr '\n' ' ') |
| |
| log "INFO" "Displaying content of $REPOS_PATH/$REPO.repo" |
| cat $REPOS_PATH/$REPO.repo |
| $REPOCLOSURE $CLOSUREOPTS $(echo $dlrn_repos) -c $REPOS_PATH/$REPO.repo |
| return 0 |
| # (TODO) there are some known issues in deps repos that break repoclosure so i'm not taking it |
| # into account althoug i'm running it for reporting. Once all issues are fixed we can uncomment |
| # following lines |
| #if [ $? -ne 0 ]; then |
| # return 1 |
| #fi |
| # set +x |
| } |
| |
| for line in $(cat $CREPOS_FILE|grep -v -e "^$") |
| do |
| REPO=$line |
| RELEASE=$(echo $REPO|awk -F'-' '{print $3}') |
| PHASE=$(echo $REPO|cut -d- -f4-) |
| |
| if [ -z "$REPO" -o -z "$RELEASE" -o -z "$PHASE" ]; then |
| break |
| fi |
| |
| generate_config $REPO $RELEASE $PHASE |
| install_temp_repo $REPO $RELEASE $PHASE |
| |
| if [ $? -ne 0 ]; then |
| log "ERROR" "FAILURE testing new configuration for $REPO" |
| SUMMARY="$SUMMARY \nERROR testing new configuration for $REPO" |
| FAILED=1 |
| else |
| log "INFO" "SUCCESS testing new configuration for $REPO" |
| SUMMARY="$SUMMARY \nSUCCESS testing new configuration for $REPO" |
| fi |
| done |
| |
| log "INFO" "Summary of test results:" |
| echo -e $SUMMARY |
| exit $FAILED |