Bug 2101840

Summary: Leapp fails while executing an SQL insert request containing the hostname (leapp.db)
Product: Red Hat Enterprise Linux 7 Reporter: Christophe Besson <cbesson>
Component: leappAssignee: Leapp team <leapp-notifications>
Status: CLOSED ERRATA QA Contact: Upgrades and Supportability <upgrades-and-supportability>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.9CC: mhecko, mmoran, pstodulk
Target Milestone: rcKeywords: Triaged
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: leapp-0.15.0-1.el7_9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-09 12:33:16 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Christophe Besson 2022-06-28 14:07:08 UTC
Description of problem:
Leapp fails while executing an SQL insert request containing the hostname (leapp.db)

Version-Release number of selected component (if applicable):
leapp-upgrade-el7toel8-0.16.0-4.el7_9

How reproducible:
Always for the customer.

Actual results:
# leapp preupgrade --target 8.4
Traceback (most recent call last):
  File "/bin/leapp", line 9, in <module>
    load_entry_point('leapp==0.14.0', 'console_scripts', 'leapp')()
  File "/usr/lib/python2.7/site-packages/leapp/cli/__init__.py", line 37, in main
    cli.command.execute('leapp version {}'.format(VERSION))
  File "/usr/lib/python2.7/site-packages/leapp/utils/clicmd.py", line 106, in execute
    args.func(args)
  File "/usr/lib/python2.7/site-packages/leapp/utils/clicmd.py", line 128, in called
    self.target(args)
  File "/usr/lib/python2.7/site-packages/leapp/cli/commands/upgrade/breadcrumbs.py", line 94, in wrapper
    return f(*args, breadcrumbs=breadcrumbs, **kwargs)
  File "/usr/lib/python2.7/site-packages/leapp/cli/commands/preupgrade/__init__.py", line 48, in preupgrade
    logger = configure_logger('leapp-preupgrade.log')
  File "/usr/lib/python2.7/site-packages/leapp/logger/__init__.py", line 88, in configure_logger
    _logger.info('Logging has been initialized')
  File "/usr/lib64/python2.7/logging/__init__.py", line 1149, in info
    self._log(INFO, msg, args, **kwargs)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in _log
    self.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1278, in handle
    self.callHandlers(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 1318, in callHandlers
    hdlr.handle(record)
  File "/usr/lib64/python2.7/logging/__init__.py", line 749, in handle
    self.emit(record)
  File "/usr/lib/python2.7/site-packages/leapp/logger/__init__.py", line 40, in emit
    self._do_emit(log_data)
  File "/usr/lib/python2.7/site-packages/leapp/logger/__init__.py", line 45, in _do_emit
    Audit(**log_data).store()
  File "/usr/lib/python2.7/site-packages/leapp/utils/audit/__init__.py", line 88, in store
    self.do_store(connection)
  File "/usr/lib/python2.7/site-packages/leapp/utils/audit/__init__.py", line 359, in do_store
    super(Audit, self).do_store(connection)
  File "/usr/lib/python2.7/site-packages/leapp/utils/audit/__init__.py", line 215, in do_store
    super(DataSource, self).do_store(connection)
  File "/usr/lib/python2.7/site-packages/leapp/utils/audit/__init__.py", line 162, in do_store
    (self.context, self.hostname))
sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

Additional info:
- The issue happens in /usr/lib/python2.7/site-packages/leapp/utils/audit/__init__.py

159     def do_store(self, connection):
160         super(Host, self).do_store(connection)
161         import sys; sys.stdout.write("DO_STORE: hostname=%s context=%s\n" % (self.hostname, self.context))     # <===
162         connection.execute('INSERT OR IGNORE INTO host (context, hostname) VALUES(?, ?)',
163                            (self.context, self.hostname))
164         cursor = connection.execute('SELECT id FROM host WHERE context = ? AND hostname = ?',
165                                     (self.context, self.hostname))
166         self._host_id = cursor.fetchone()[0]

- Printing the hostname shows the following data (line 161)

DO_STORE: hostname='HOSTNAME.XXX.YYY.ZZZ     HOSTNAME   ALIAS.XXX.YYY.ZZZ        ALIAS' context='TESTING-CONTEXT'

=> it contains both fqdn hostname and aliases (on my test box, it prints "foo.bar" only).
=> this is the content of the /etc/hosts file for the host IP

- the customer had duplicate entries in /etc/hosts for the host IP. Removing the duplicate fixed the issue for the customer (but it didn't help me to reproduce the issue, it's weird).

Comment 3 Petr Stodulka 2022-08-17 15:55:49 UTC
The upstream PR fixing the issue:
    https://github.com/oamg/leapp/pull/790

The hostname on the machine is invalid. In such a case we will replace the invalid hostname in leapp reports & db by the 'invalid.hostname' string.

Comment 4 Petr Stodulka 2022-08-23 16:40:18 UTC
The PR has been merged in the upstream.

Comment 9 errata-xmlrpc 2022-11-09 12:33:16 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (leapp and leapp-repository bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:7895