From 7bdde031abaabdd781c48168272bf3a3c06cd05a Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Fri, 21 Jul 2023 17:23:34 +0200 Subject: [PATCH] Ensure we always have an integer when yum history tid is fetched (#157) We have had this trace in our Jenkins instance: ``` Jul 20 14:44:50 WARNING An error occurred in `exec_on_hosts_on_error_continue` for host 172.16.210.26 Backtrace: Traceback (most recent call last): File "/home/vates/workspace/8.3 storage-main/lib/pool.py", line 64, in exec_on_hosts_on_error_continue func(h) File "/home/vates/workspace/8.3 storage-main/pkgfixtures.py", line 38, in host.pool.exec_on_hosts_on_error_continue(lambda h: h.yum_restore_saved_state()) File "/home/vates/workspace/8.3 storage-main/lib/host.py", line 322, in yum_restore_saved_state self.saved_rollback_id, '-y' File "/home/vates/workspace/8.3 storage-main/lib/host.py", line 57, in ssh decode=decode) File "/home/vates/workspace/8.3 storage-main/lib/commands.py", line 149, in ssh raise result_or_exc lib.commands.SSHCommandFailed: SSH command (yum history rollback --enablerepo=xcp-ng-base,xcp-ng-testing,xcp-ng-updates The -y) failed with return code 1: Loaded plugins: fastestmirror Bad transaction ID given Error: Failed history rollback, no transaction ``` We don't have an integer during yum rollback here. Only a string: "The". Because we don't know how this problem happens, it is interesting to make sure to always have an integer when the transaction is started and also to throw an exception with the full yum command output in case of problem. Signed-off-by: Ronan Abhamon --- lib/host.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/host.py b/lib/host.py index 180770b25..dbb6ec3af 100644 --- a/lib/host.py +++ b/lib/host.py @@ -261,7 +261,7 @@ def get_last_yum_history_tid(self): [...] """ try: - history = self.ssh(['yum', 'history', 'list', '--noplugins']).splitlines() + history_str = self.ssh(['yum', 'history', 'list', '--noplugins']) except commands.SSHCommandFailed as e: # yum history list fails if the list is empty, and it's also not possible to rollback # to before the first transaction, so "0" would not be appropriate as last transaction. @@ -269,8 +269,13 @@ def get_last_yum_history_tid(self): logging.info('Install and remove a small package to workaround empty yum history.') self.yum_install(['gpm-libs']) self.yum_remove(['gpm-libs']) - history = self.ssh(['yum', 'history', 'list', '--noplugins']).splitlines() - return history[2].split()[0] + history_str = self.ssh(['yum', 'history', 'list', '--noplugins']) + + history = history_str.splitlines() + try: + return int(history[2].split()[0]) + except ValueError: + raise Exception('Unable to parse correctly last yum history tid. Output\n:' + history_str) def yum_install(self, packages, enablerepo=None): logging.info('Install packages: %s on host %s' % (' '.join(packages), self)) @@ -318,9 +323,12 @@ def yum_restore_saved_state(self): "Can't restore previous state without a package list: no saved packages list" assert self.saved_rollback_id is not None, \ "Can't restore previous state without a package list: no rollback id" + + assert isinstance(self.saved_rollback_id, int) + self.ssh([ 'yum', 'history', 'rollback', '--enablerepo=xcp-ng-base,xcp-ng-testing,xcp-ng-updates', - self.saved_rollback_id, '-y' + str(self.saved_rollback_id), '-y' ]) pkgs = self.packages() if self.saved_packages_list != pkgs: