mirror of
https://tvoygit.ru/Djam/r11-builder-agent.git
synced 2025-02-23 18:32:46 +00:00
add test to make sure that we have not same version is repos
This commit is contained in:
parent
0da1e4e7a2
commit
88e2ecb827
2 changed files with 92 additions and 14 deletions
22
build-rpm.sh
22
build-rpm.sh
|
@ -188,7 +188,7 @@ probe_cpu
|
|||
test_rpm() {
|
||||
# Rerun tests
|
||||
PACKAGES=${packages} \
|
||||
chroot_path=$chroot_path \
|
||||
chroot_path="$($MOCK_BIN --configdir=$config_dir --print-root-path)" \
|
||||
use_extra_tests=$use_extra_tests
|
||||
|
||||
test_code=0
|
||||
|
@ -205,7 +205,7 @@ test_rpm() {
|
|||
echo "--> Re-running tests on `date -u`" >> $test_log
|
||||
prefix='rerun-tests-'
|
||||
arr=($packages)
|
||||
cd "$build_package"
|
||||
pushd "$build_package"
|
||||
for package in ${arr[@]} ; do
|
||||
echo "--> Downloading '$package'..." >> $test_log
|
||||
wget http://file-store.rosalinux.ru/api/v1/file_stores/$package --content-disposition --no-check-certificate
|
||||
|
@ -215,23 +215,17 @@ test_rpm() {
|
|||
exit $rc
|
||||
fi
|
||||
done
|
||||
cd ..
|
||||
# (tpg) TODO fix running tests with cached-chroot
|
||||
# if [ "${CACHED_CHROOT_SHA1}" != '' ]; then
|
||||
# echo "--> Uses cached chroot with sha1 '$CACHED_CHROOT_SHA1'..." >> $test_log
|
||||
# $MOCK_BIN --chroot "urpmi.removemedia -a"
|
||||
# $MOCK_BIN --readdrepo -v --configdir $config_dir --no-cleanup-after --no-clean --update
|
||||
# else
|
||||
$MOCK_BIN --init --configdir $config_dir -v --no-cleanup-after
|
||||
# fi
|
||||
|
||||
OUTPUT_FOLDER="$build_package"
|
||||
fi
|
||||
popd
|
||||
OUTPUT_FOLDER="$build_package"
|
||||
fi
|
||||
|
||||
echo '--> Checking if rpm packages can be installed.' >> $test_log
|
||||
$MOCK_BIN -v --init --configdir $config_dir $OUTPUT_FOLDER/*.src.rpm >> "${test_log}".tmp
|
||||
$MOCK_BIN -v --init --configdir $config_dir --install $(ls "$OUTPUT_FOLDER"/*.rpm | grep -v .src.rpm) >> "${test_log}".tmp 2>&1
|
||||
|
||||
cat $test_log.tmp >> $test_log
|
||||
echo '--> Checking if same or newer version of the package already exists in repositories' >> $test_log 2>&1
|
||||
python /mdv/check_newer_versions.py $chroot_path >> $test_log 2>&1
|
||||
echo "--> Tests finished at `date -u`" >> $test_log
|
||||
echo 'Test code output: ' $test_code >> $test_log 2>&1
|
||||
rm -f $test_log.tmp
|
||||
|
|
84
check_newer_versions.py
Executable file
84
check_newer_versions.py
Executable file
|
@ -0,0 +1,84 @@
|
|||
#!/usr/bin/python2
|
||||
|
||||
#
|
||||
# Read all rpm packages in chroot directory and check
|
||||
# if packages with newer or same version are available in repositories
|
||||
#
|
||||
# If yes, fail the test (return non-zero)
|
||||
#
|
||||
|
||||
import sys
|
||||
import glob
|
||||
import os.path
|
||||
import rpm
|
||||
import rpm5utils.miscutils
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit('Usage: %s chroot_path' % sys.argv[0])
|
||||
|
||||
chroot_path = sys.argv[1]
|
||||
|
||||
ts = rpm.TransactionSet()
|
||||
ts.setVSFlags(~(rpm.RPMVSF_NEEDPAYLOAD))
|
||||
|
||||
# We will check all packages and set exit_code to 1
|
||||
# if some of them fail the test
|
||||
exit_code = 0
|
||||
|
||||
for pkg in glob.glob(chroot_path + "/*.rpm"):
|
||||
# Do not check src.srm
|
||||
# (can't exclude them in the glob expression above,
|
||||
# since glob doesn't support exclusion patterns)
|
||||
if os.path.basename(pkg).endswith("src.rpm"):
|
||||
continue
|
||||
|
||||
fdno = os.open(pkg, os.O_RDONLY)
|
||||
|
||||
hdr = ts.hdrFromFdno(fdno)
|
||||
name = hdr['name']
|
||||
version = hdr['version']
|
||||
release = hdr['release']
|
||||
if hdr['epoch']:
|
||||
epoch = hdr['epoch']
|
||||
else:
|
||||
epoch = 0
|
||||
if hdr['distepoch']:
|
||||
distepoch = hdr['distepoch']
|
||||
else:
|
||||
distepoch = 0
|
||||
|
||||
# Useful for local tests without chrooting
|
||||
# p = os.popen("urpmq --evrd " + name + " 2>&1 | sed 's/|/\\n/g'")
|
||||
|
||||
p = os.popen("sudo chroot " + chroot_path + " urpmq --wget --wget-options --auth-no-challenge --evrd " + name + " 2>&1 | sed 's/|/\\n/g'")
|
||||
for existing_pkg in p.readlines():
|
||||
if "Unknown option:" in existing_pkg:
|
||||
print "This urpmq doesn't support --evrd option, the test will be skipped"
|
||||
sys.exit(0)
|
||||
|
||||
# existing_pkg should look like "name: epoch:version-release:distepoch"
|
||||
try:
|
||||
(name, evrd) = existing_pkg.split()
|
||||
evrd_array = evrd.split(":")
|
||||
ex_epoch = evrd_array[0]
|
||||
ex_distepoch = evrd_array[2]
|
||||
(ex_version, ex_release) = evrd_array[1].split("-")
|
||||
except:
|
||||
# urpmq output line is not recognized - just print it "as is"
|
||||
print existing_pkg
|
||||
continue
|
||||
|
||||
res = rpm5utils.miscutils.compareDEVR( (distepoch, epoch, version, release), (ex_distepoch, ex_epoch, ex_version, ex_release) )
|
||||
if res < 1:
|
||||
print "A package with the same name (" + name + ") and same or newer version (" + evrd + ") already exists in repositories!"
|
||||
exit_code = 1
|
||||
# Matching package has been found - no need to parse other lines of "urpmq --evrd"
|
||||
break
|
||||
|
||||
del hdr
|
||||
os.close(fdno)
|
||||
|
||||
del ts
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
Loading…
Add table
Reference in a new issue