From 49123997cc6db07f2df335a6fe276534248dc767 Mon Sep 17 00:00:00 2001 From: prestonsn Date: Mon, 11 Jul 2022 17:51:02 +0000 Subject: [PATCH] Fix missing error when repo build script setup-repo.sh fails. --- pytests/conftest.py | 7 ++++++- pytests/repo/setup-repo.sh | 17 ++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pytests/conftest.py b/pytests/conftest.py index 6e088f2df..05babf781 100644 --- a/pytests/conftest.py +++ b/pytests/conftest.py @@ -101,7 +101,12 @@ def __init__(self, cli_args=None): self.config.update(cli_args) self.config['distribution'] = os.environ.get('DIST', 'photon') script = os.path.join(self.config['test_path'], 'repo/setup-repo.sh') - self.run(['sh', script, self.config['repo_path']]) + ret = self.run(['sh', script, self.config['repo_path']]) + if ret['retval']: + pytest.exit("An error occured while running {}, stdout: \n{}".format( + script, + "\n".join(ret['stdout']) + )) self.tdnf_config = configparser.ConfigParser() self.tdnf_config.read(os.path.join(self.config['repo_path'], 'tdnf.conf')) diff --git a/pytests/repo/setup-repo.sh b/pytests/repo/setup-repo.sh index 64dc5834c..1e1acd314 100755 --- a/pytests/repo/setup-repo.sh +++ b/pytests/repo/setup-repo.sh @@ -12,13 +12,22 @@ if [ $# -ne 1 ]; then exit 1 fi -fix_dir_perms() +function fix_dir_perms() { chmod 755 ${TEST_REPO_DIR} find ${TEST_REPO_DIR} -type d -exec chmod 0755 {} \; find ${TEST_REPO_DIR} -type f -exec chmod 0644 {} \; } +## used to check return code for each command. +function check_err { + rc=$? + if [ $rc -ne 0 ]; then + echo $1 + exit $rc + fi +} + TEST_REPO_DIR=$1 if [ -d $1 ]; then echo "Repo already exists" @@ -56,6 +65,7 @@ EOF #generate a key non interactively. this is used in testing #repogpgcheck plugin gpg --batch --generate-key ${TEST_REPO_DIR}/gpgkeydata +check_err "Failed to generate gpg key." cat << EOF > ~/.rpmmacros %_gpg_name tdnftest@tdnf.test @@ -69,8 +79,10 @@ done echo building packages rpmbuild --define "_topdir ${BUILD_PATH}" \ -r ${BUILD_PATH} -ba ${REPO_SRC_DIR}/*.spec +check_err "Failed to build packages." rpmsign --addsign ${BUILD_PATH}/RPMS/*/*.rpm cp -r ${BUILD_PATH}/RPMS ${PUBLISH_PATH} +check_err "Failed to sign built packages." # save key to later be imported: mkdir -p ${PUBLISH_PATH}/keys @@ -79,12 +91,15 @@ gpg --armor --export tdnftest@tdnf.test > ${PUBLISH_PATH}/keys/pubkey.asc createrepo ${PUBLISH_PATH} > /dev/null 2>&1 modifyrepo ${REPO_SRC_DIR}/updateinfo-1.xml ${PUBLISH_PATH}/repodata +check_err "Failed to modify repo with updateinfo-1.xml." modifyrepo ${REPO_SRC_DIR}/updateinfo-2.xml ${PUBLISH_PATH}/repodata +check_err "Failed to modify repo with updateinfo-2.xml." #gpg sign repomd.xml gpg --batch --passphrase-fd 0 \ --pinentry-mode loopback \ --detach-sign --armor ${PUBLISH_PATH}/repodata/repomd.xml +check_err "Failed to gpg sign repomd.xml." cat << EOF > ${TEST_REPO_DIR}/yum.repos.d/photon-test.repo [photon-test]