Skip to content
Snippets Groups Projects
Commit 73c4d073 authored by Aurélien Gounon's avatar Aurélien Gounon
Browse files

add cta-versionlock helper script

parent 740e3847
Branches
Tags
No related merge requests found
......@@ -3,6 +3,7 @@
## Summary
### Features
- cta/CTA#983 Add cta-versionlock helper script to cta-release package
### Bug fixes
- cta/CTA#1029 Fix segmentatin fault in frontend when list repacks of a tape that has been deleted in the catalogue
......
......@@ -73,4 +73,5 @@ install (FILES ${KEY_FILES}
install (FILES ../continuousintegration/docker/ctafrontend/cc7/etc/yum/pluginconf.d/versionlock.list
DESTINATION ${CMAKE_INSTALL_SYSCONFDIR}/yum/pluginconf.d
RENAME versionlock.cta)
install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/cta-versionlock
DESTINATION usr/${CMAKE_INSTALL_BINDIR})
#!/usr/bin/python
import os.path
import sys
import re
from rpmUtils.miscutils import splitFilename
from collections import defaultdict
vfiles = {
'cta': '/etc/yum/pluginconf.d/versionlock.cta',
'yum': '/etc/yum/pluginconf.d/versionlock.list'
}
versions = defaultdict(dict)
summary = defaultdict(list)
actions = ('check', 'apply', 'forceupdate', 'clear')
retcode = 0
try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError
def usage():
print("\n%s: command line tool to manage cta packages versionlock\n \
\n \
usage: %s check|apply|forceupdate|clear\n \
check: show cta versionlock status\n \
apply: add cta versions to versionlock file\n \
forceupdate: add cta versions to versionlock file and overwrite already defined versions\n \
clear: remove all cta versions from versionlock file\n \
" % (sys.argv[0], sys.argv[0]))
exit(1)
# Compare versions in both version lists
def matchPkg(pkglist):
for p, version in pkglist.items():
try:
versions['yum'][p]
except:
summary['missing'].append(p)
continue
else:
if versions['yum'][p][:-1] == version[:-1]:
summary['present'].append(p)
else:
summary['wrong_version'].append(p)
# add cta versions to yum versionlock file
def addtoVfile(pkglist):
with open(vfiles['yum'], 'a' ) as f:
for p in pkglist:
(e, v, r, a) = versions['cta'][p][:]
package = ("%s:%s-%s-%s.%s" % (e, p, v, r, a))
f.write(package + '\n')
# force update existing versions in yum versionlock with cta one
def updateVfile(pkglist):
with open(vfiles['yum'], 'r+') as f:
content = f.read()
for p in pkglist:
ver = {}
for t in 'yum', 'cta':
(e, v, r, a) = versions[t][p][:]
ver[t] = ("%s:%s-%s-%s.%s" % (e, p, v, r, a))
content = re.sub(ver['yum'], ver['cta'], content)
f.seek(0)
f.write(content)
f.truncate()
# clear cta versions from yum versionlock
def clearPkgs(pkglist):
with open(vfiles['yum'], 'r+') as f:
content = f.read()
for p in pkglist:
(e, v, r, a) = versions['cta'][p][:]
line = ("%s:%s-%s-%s.%s\n" % (e, p, v, r, a))
content = re.sub(line, '', content)
f.seek(0)
f.write(content)
f.truncate()
# check arguments
if len(sys.argv) != 2:
usage()
action = sys.argv[1]
if action not in actions:
print("Error: option %s is not valid" % sys.argv[1])
usage()
# read version files
for fname, vfile in vfiles.items():
if not os.path.isfile(vfile):
raise FileNotFoundError("file %s not found" % vfile)
with open(vfile) as f:
plist = f.read().splitlines()
for p in plist:
if p == "" or p.startswith('#'):
continue
(n, v, r, e, a) = splitFilename(p)
versions[fname][n] = [e, v, r, a]
# check if packages versions exist in yum versionlock file (ignore arch)
matchPkg(versions['cta'])
# return summary
if (action == 'check'):
for status, content in summary.items():
print("\n=> %s: (%s/%s)" % (status, len(content), len(versions['cta'])))
print("\n".join(content))
if ("missing" in summary or "wrong_version" in summary):
retcode = 2
# add cta packages to versionlock file
elif (action == 'apply'):
if "missing" in summary:
print("\nAdding %s packages to version lock file:" % len(summary['missing']))
print("\n".join(summary['missing']))
addtoVfile(summary['missing'])
else:
print("\nNothing to do")
if "wrong_version" in summary:
print("\nWARNING: the following packages have a different version specified in versionlock file:")
print('\n'.join(summary['wrong_version']))
print("\nThey will not be changed unless you run %s with the 'forceupdate' option" % sys.argv[0])
retcode = 2
# overwrite existing versions in versionlock file
elif (action == 'forceupdate'):
if "wrong_version" in summary:
print("\nUpdating %s packages version in versionlock file:" % len(summary['wrong_version']))
for p in summary['wrong_version']:
print("%s: previous %s, new %s" % (p, ':'.join(versions['yum'][p]), ':'.join(versions['cta'][p])))
updateVfile(summary['wrong_version'])
if "missing" in summary:
print("\nAdding %s packages to version lock file:" % len(summary['missing']))
print("\n".join(summary['missing']))
addtoVfile(summary['missing'])
if (not summary['missing'] and not summary['wrong_version']):
print("\nNothing to do")
# remove cta versions from versionlock file
elif (action == 'clear'):
if versions['cta']:
clearPkgs(versions['cta'])
print("\nRemoving %s packages from versionlock file:" % len(versions['cta']))
print("\n".join(versions['cta']))
else:
print("\nNothing to do")
print('\n')
exit(retcode)
......@@ -513,20 +513,20 @@ Group: Application/CTA
Requires: yum-plugin-versionlock
%description -n cta-release
Repository configuration for CTA dependencies
This package contains .repo files, gpg keys and yum-versionlock configuration fro CTA
This package contains .repo files, gpg keys and yum-versionlock configuration for CTA
%files -n cta-release
%defattr(0644,root,root)
%config(noreplace) %{_sysconfdir}/yum.repos.d/*
%{_sysconfdir}/pki/rpm-gpg/*
%{_sysconfdir}/yum/pluginconf.d/versionlock.cta
%defattr(-,root,root)
%attr(0644,root,root) %config(noreplace) %{_sysconfdir}/yum.repos.d/*
%attr(0644,root,root) %{_sysconfdir}/pki/rpm-gpg/*
%attr(0644,root,root) %{_sysconfdir}/yum/pluginconf.d/versionlock.cta
%attr(0755,root,root) %{_bindir}/cta-versionlock
%post -n cta-release
cat << EOF
------
CTA versionlock file installed as "%{_sysconfdir}/yum/pluginconf.d/versionlock.cta"
Remember to add its content to "%{_sysconfdir}/yum/pluginconf.d/versionlock.list" to enable it.
------
EOF
/usr/bin/cta-versionlock apply
%preun -n cta-release
/usr/bin/cta-versionlock clear
%changelog
* Wed Aug 18 2021 volodymyr.yurchenko (at) cern.ch - 4.1-1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment