Bug 39903 - univention-pkgdb-scan fails on old systems / multiarch / with unsatisfied dependencies
univention-pkgdb-scan fails on old systems / multiarch / with unsatisfied dep...
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: pkgdb
UCS 4.1
Other Linux
: P5 normal (vote)
: UCS 4.2
Assigned To: Janek Walkenhorst
Felix Botner
: interim-2
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2015-11-12 12:05 CET by Janek Walkenhorst
Modified: 2017-04-04 18:28 CEST (History)
5 users (show)

See Also:
What kind of report is it?: Bug Report
What type of bug is this?: 4: Minor Usability: Impairs usability in secondary scenarios
Who will be affected by this bug?: 4: Will affect most installed domains
How will those affected feel about the bug?: 3: A User would likely not purchase the product
User Pain: 0.274
Enterprise Customer affected?: Yes
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number: 2015111121000749
Bug group (optional):
Max CVSS v3 score:
hahn: Patch_Available+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Janek Walkenhorst univentionstaff 2015-11-12 12:05:38 CET
With systems updated from around UCS 1.3 to UCS 4.0 univention-pkgdb-scan fails

Traceback (most recent call last):
  File "/usr/sbin/univention-pkgdb-scan", line 37, in <module>
    univention.pkgdb.main()
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 577, in main
    return action_scan(connection, cursor, config_registry)
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 482, in action_scan
    scan_and_store_packages(cursor, sysname, fake_null)
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 436, in scan_and_store_packages
    cursor.execute(insert_statement)
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 259, in execute
    self.executemany(operation, (params,))
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 289, in executemany
    raise DatabaseError("error '%s' in '%s'" % (msg, sql))
pg.DatabaseError: error 'FEHLER:  doppelter Schlüsselwert verletzt Unique-Constraint »packages_on_systems_pkey«

because apt_pkg.Cache().packages contains a few packages (e.g. "lilo") twice.
Comment 1 Tim Petersen univentionstaff 2015-11-12 12:06:37 CET
2015111121000749
Comment 2 Tim Petersen univentionstaff 2015-11-12 12:06:58 CET
Cleaning the apt cache doesn't work as a workaround
Comment 3 Philipp Hahn univentionstaff 2015-11-16 10:29:44 CET
+1
Comment 4 Philipp Hahn univentionstaff 2015-11-16 11:07:24 CET
Traceback (most recent call last):
  File "/usr/sbin/univention-pkgdb-scan", line 37, in <module>
    univention.pkgdb.main()
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 577, in main
    return action_scan(connection, cursor, config_registry)
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 482, in action_scan
    scan_and_store_packages(cursor, sysname, fake_null)
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 436, in scan_and_store_packages
    cursor.execute(insert_statement)
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 259, in execute
    self.executemany(operation, (params,))
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 289, in executemany
    raise DatabaseError("error '%s' in '%s'" % (msg, sql))
pg.DatabaseError: error 'FEHLER:  doppelter Schl\xc3\xbcsselwert verletzt Unique-Constraint \xc2\xbbpackages_on_syst
ems_pkey\xc2\xab
DETAIL:  Schl\xc3\xbcssel \xc2\xbb(sysname, pkgname)=(master, lilo)\xc2\xab existiert bereits.'


$ python -c '
import apt_pkg, pprint
apt_pkg.init()
c = apt_pkg.Cache()
pprint.pprint([p for p in c.packages if p.name == "lilo"])'
[<apt_pkg.Package object: name:'lilo' section: 'admin' id:540>,
 <apt_pkg.Package object: name:'lilo' section: '' id:6938>]
Comment 5 Drees Dormann univentionstaff 2016-06-20 13:01:58 CEST
# apt-cache policy lilo
lilo:
  Installiert:           (keine)
  Installationskandidat: 1:23.2-4.26.201403130151
  Versionstabelle:
     1:23.2-4.26.201403130151 0
        500 http://192.168.0.10/build2/ ucs_4.0-0/i386/ Packages
        500 http://univention-repository.knut.univention.de/4.0/maintained/ 4.0-0/i386/ Packages





architecture i386
current_state 0
current_ver None
essential False
get_fullname <built-in method get_fullname of apt_pkg.Package object at 0xb748a5cc>
has_provides False
has_versions True
id 567
important False
inst_state 0
name lilo
provides_list []
section admin
selected_state 0
version_list [<apt_pkg.Version object: Pkg:'lilo' Ver:'1:23.2-4.26.201403130151' Section:'admin'  Arch:'i386' Size:299408 ISize:686080 Hash:29733 ID:2202 Priority:4>]


architecture none
current_state 0
current_ver None
essential False
get_fullname <built-in method get_fullname of apt_pkg.Package object at 0xb748a59c>
has_provides False
has_versions False
id 46369
important False
inst_state 0
name lilo
provides_list []
section 
selected_state 0
version_list []




# apt-cache show lilo
Package: lilo
Priority: optional
Section: admin
Installed-Size: 670
Maintainer: Joachim Wiedorn <ad_debian@joonet.de>
Architecture: i386
Version: 1:23.2-4.26.201403130151
Depends: perl, libc6 (>= 2.3), libdevmapper1.02.1 (>= 2:1.02.20), debconf (>= 0.5) | debconf-2.0
Pre-Depends: dpkg (>= 1.15.7.2)
Suggests: lilo-doc
Filename: 4.0-0/i386/lilo_23.2-4.26.201403130151_i386.deb
Size: 299408
MD5sum: 34787856d816af81fe687ea6d230e6bc
SHA1: fa3a685ec81d69dc9717455803c638d70cf85bd7
SHA256: dfd14ba5d1cda5ca223c5f16825ebf6ad1a19fb866a0f38eebe5db2b15853c8b
Description: LInux LOader - the classic OS boot loader
 You can use LILO to manage your Master Boot Record (with a simple text
 screen, text menu or colorful splash graphics) or call LILO from other
 Boot-Loaders to jump-start the Linux kernel.
 .
 This package contains lilo (the installer) and boot-record-images to
 install Linux, DOS and generic Boot Sectors for other OSes.
Homepage: http://lilo.alioth.debian.org/
Comment 6 Philipp Hahn univentionstaff 2016-12-16 16:28:32 CET
Again with UCS-4.2 update: the traceback is ½M lines long!

# univention-pkgdb-scan &>/tmp/log
# wc -l /tmp/log 
566561 /tmp/log
# head -n28 /tmp/log 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Traceback (most recent call last):
  File "/usr/sbin/univention-pkgdb-scan", line 37, in <module>
    univention.pkgdb.main()
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 577, in main
    return action_scan(connection, cursor, config_registry)
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 482, in action_scan
    scan_and_store_packages(cursor, sysname, fake_null)
  File "/usr/lib/pymodules/python2.7/univention/pkgdb.py", line 436, in scan_and_store_packages
    cursor.execute(insert_statement)
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 259, in execute
    self.executemany(operation, (params,))
  File "/usr/lib/python2.7/dist-packages/pgdb.py", line 289, in executemany
    raise DatabaseError("error '%s' in '%s'" % (msg, sql))
pg.DatabaseError: error 'FEHLER:  doppelter Schlüsselwert verletzt Unique-Constraint »packages_on_systems_pkey«
DETAIL:  Schlüssel »(sysname, pkgname)=(master41, libdb5.3)« existiert bereits.
' in '
        INSERT INTO packages_on_systems (scandate,
                                         sysname,
                                         currentstate,
                                         inststate,
                                         inststatus,
                                         pkgname,
                                         selectedstate,
                                         vername)

# python -c '
import apt_pkg
apt_pkg.init()
cache = apt_pkg.Cache()
pkgs = {}
for package in cache.packages:
  pkgs.setdefault(package.name, []).append(package)

for name, packages in pkgs.iteritems():
  if len(packages) == 1:
    continue
  print name, ' '.join(p.get_fullname() for p in packages)
'
libsasl2-2 libsasl2-2:amd64 libsasl2-2:i386
libsasl2-modules libsasl2-modules:amd64 libsasl2-modules:i386
libdb5.3 libdb5.3:amd64 libdb5.3:i386
zlib1g zlib1g:amd64 zlib1g:i386
libgnutls26 libgnutls26:amd64 libgnutls26:i386
libc6 libc6:amd64 libc6:i386
libsasl2-modules-db libsasl2-modules-db:amd64 libsasl2-modules-db:i386
libldap-2.4-2 libldap-2.4-2:amd64 libldap-2.4-2:i386
u-boot u-boot:armhf u-boot:amd64


The APT package also contains references to packages used as dependencies; they might not be available as you see from this case: The system is amd64 and multi-arch for i386 is currently not enabled, so for example 'ia32-libs:amd64' depends on 'libc6:i386' - the former is available in amd64/Packages, while the later is only in i386/Packages.

pkgdb must be adjusted to
1) ignore "broken dependency packages" and
2) either be multi-arch aware or 
3) should filter out unavailable packages testing "p.has_versions()"
4) stop printing lost tracebacks

Ad 1:
--- /usr/share/pyshared/univention/pkgdb.py~    2016-08-31 12:58:44.000000000 +0200
+++ /usr/share/pyshared/univention/pkgdb.py     2016-12-15 12:00:24.711809000 +0100
@@ -417,6 +417,8 @@
        cursor.execute(delete_packages, {'sysname': sysname, })
        insert_values = []
        for package in scan_and_store_packages.cache.packages:
+               if not package.has_versions:
+                       continue
                parameters = {'sysname':       sysname,
                              'currentstate':  package.current_state,
                              'inststate':     package.inst_state,


As soon as you enable multiarch, pkgdb breaks completely:
ucr set repository/online/architectures='i386 amd64'
dpkg --add-architecture i386
apt-get -qq update
univention-pkgdb-scan &>/tmp/log  ; echo $? ; wc -l /tmp/log
# 1
# 680789 /tmp/log

Ad 3:
--- /usr/share/pyshared/univention/pkgdb.py~    2016-08-31 12:58:44.000000000 +0200
+++ /usr/share/pyshared/univention/pkgdb.py     2016-12-15 12:13:57.019809000 +0100
@@ -383,7 +383,7 @@
        cursor.execute(delete_system  , {'sysname': sysname, })
        connection.commit()

-def scan_and_store_packages(cursor, sysname, fake_null=False):
+def scan_and_store_packages(cursor, sysname, fake_null=False, architecture=None):
        '''updates the system <sysname> with the current package state
        if <fake_null> is True put '' instead of None in the vername field'''
        delete_packages = '''
@@ -417,6 +417,10 @@
        cursor.execute(delete_packages, {'sysname': sysname, })
        insert_values = []
        for package in scan_and_store_packages.cache.packages:
+               if not package.has_versions:
+                       continue
+               if architecture and architecture != package.architecture:
+                       continue
                parameters = {'sysname':       sysname,
                              'currentstate':  package.current_state,
                              'inststate':     package.inst_state,
@@ -479,7 +483,7 @@
                # retry for old schema
                sql_put_sys_in_systems_no_architecture(cursor, sysname, sysversion, sysrole, ldaphostdn)
                fake_null = True # old schema has NOT NULL, thus we have to use '' instead of None
-       scan_and_store_packages(cursor, sysname, fake_null)
+       scan_and_store_packages(cursor, sysname, fake_null, architecture)
        connection.commit()
        log('end of scan for system %r' % (sysname, ))
        return 0
Comment 7 Philipp Hahn univentionstaff 2016-12-16 16:57:33 CET
r75356 | Bug #39903 pkgdb: Ignore not existing referenced packages
 apply 1) for now to allow upgrades to UCS-4.2-0

Package: univention-pkgdb
Version: 10.0.0-3A~4.2.0.201612161654
Branch: ucs_4.2-0
Comment 8 Janek Walkenhorst univentionstaff 2017-02-27 14:54:17 CET
univention-pkgdb (10.0.0-4) unstable; urgency=medium

  * Bug #39903: Ignore packages from wrong architecture
  * Bug #35147: fix --fill-testdb
Comment 9 Felix Botner univentionstaff 2017-02-28 18:05:56 CET
still happens on 10.200.7.200
Comment 10 Felix Botner univentionstaff 2017-02-28 18:08:48 CET
sorry, python-univention-pkgdb was not up-to-date
Comment 11 Felix Botner univentionstaff 2017-02-28 18:11:30 CET
OK - works on old/new systems and
Comment 12 Stefan Gohmann univentionstaff 2017-04-04 18:28:45 CEST
UCS 4.2 has been released:
 https://docs.software-univention.de/release-notes-4.2-0-en.html
 https://docs.software-univention.de/release-notes-4.2-0-de.html

If this error occurs again, please use "Clone This Bug".