Skip to content

Commit

Permalink
osmorphing: Add check for installed package
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi1324 committed Aug 22, 2024
1 parent e735358 commit 3df11a2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion coriolis/osmorphing/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' % (
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 3df11a2

Please sign in to comment.