From 3df11a2bf540cacdb849a319e91b87967a43b792 Mon Sep 17 00:00:00 2001 From: Cristian Matiut Date: Wed, 31 Jul 2024 18:41:50 +0300 Subject: [PATCH] osmorphing: Add check for installed package --- coriolis/osmorphing/redhat.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/coriolis/osmorphing/redhat.py b/coriolis/osmorphing/redhat.py index ea2e7f4fc..7d0fa93f7 100644 --- a/coriolis/osmorphing/redhat.py +++ b/coriolis/osmorphing/redhat.py @@ -209,6 +209,16 @@ def set_net_config(self, nics_info, dhcp): mac_addresses) self._add_net_udev_rules(net_ifaces_info) + def _has_package_installed(self, package_name): + cmd = 'rpm -q %s' % ("".join(package_name)) + try: + self._exec_cmd_chroot(cmd) + return True + except exception.CoriolisException: + LOG.warning(f"Package ${package_name} is not installed") + LOG.trace(utils.get_exception_details()) + return False + def _yum_install(self, package_names, enable_repos=[]): try: yum_cmd = 'yum install %s -y%s' % ( @@ -285,7 +295,10 @@ def pre_packages_install(self, package_names): super(BaseRedHatMorphingTools, self).pre_packages_install( package_names) self._yum_clean_all() - self._yum_install(['grubby']) + if not self._has_package_installed('grubby'): + self._yum_install(['grubby']) + else: + LOG.debug("Skipping package 'grubby' as it's already installed") def install_packages(self, package_names): enable_repos = self._get_repos_to_enable()