Kaynağa Gözat

Merge pull request #31 from aznashwan/ignore-missing-packs-sles

Ignore Exceptions while uninstalling packages on SUSE.
Nashwan Azhari 7 yıl önce
ebeveyn
işleme
22e40cae06
2 değiştirilmiş dosya ile 45 ekleme ve 2 silme
  1. 30 0
      coriolis/osmorphing/base.py
  2. 15 2
      coriolis/osmorphing/suse.py

+ 30 - 0
coriolis/osmorphing/base.py

@@ -7,11 +7,15 @@ import os
 import re
 import uuid
 
+from oslo_log import log as logging
 from six import with_metaclass
 
 from coriolis import utils
 
 
+LOG = logging.getLogger(__name__)
+
+
 class BaseOSMorphingTools(object, with_metaclass(abc.ABCMeta)):
 
     def __init__(
@@ -181,3 +185,29 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
         if self._test_path(resolv_conf_path_old):
             self._exec_cmd(
                 "sudo mv -f %s %s" % (resolv_conf_path_old, resolv_conf_path))
+
+    def _replace_fstab_entries_device_prefix(
+            self, current_prefix="/dev/sd", new_prefix="/dev/sd"):
+        fstab_chroot_path = "etc/fstab"
+        fstab_contents = self._read_file(fstab_chroot_path)
+        LOG.debug("Contents of /%s: %s", fstab_chroot_path, fstab_contents)
+        fstab_contents_lines = fstab_contents.split('\n')
+
+        found = False
+        regex = "^(%s)" % current_prefix
+        for i, line in enumerate(fstab_contents_lines):
+            if re.match(regex, line):
+                found = True
+                LOG.debug(
+                    "Found FSTAB line starting with '%s': %s" % (
+                        current_prefix, line))
+                fstab_contents_lines[i] = re.sub(regex, new_prefix, line)
+
+        if found:
+            self._event_manager.progress_update(
+                "Replacing all /etc/fstab entries prefixed with "
+                "'%s' to '%s'" % (current_prefix, new_prefix))
+            self._exec_cmd_chroot(
+                "mv -f /%s /%s.bak" % (fstab_chroot_path, fstab_chroot_path))
+            self._write_file(
+                fstab_chroot_path, "\n".join(fstab_contents_lines))

+ 15 - 2
coriolis/osmorphing/suse.py

@@ -3,9 +3,15 @@
 
 import re
 
+from oslo_log import log as logging
+
+from coriolis import utils
 from coriolis.osmorphing import base
 
 
+LOG = logging.getLogger(__name__)
+
+
 class BaseSUSEMorphingTools(base.BaseLinuxOSMorphingTools):
     def _check_os(self):
         os_release = self._get_os_release()
@@ -59,5 +65,12 @@ class BaseSUSEMorphingTools(base.BaseLinuxOSMorphingTools):
             'zypper --non-interactive install %s' % " ".join(package_names))
 
     def uninstall_packages(self, package_names):
-        self._exec_cmd_chroot(
-            'zypper --non-interactive remove %s' % " ".join(package_names))
+        try:
+            self._exec_cmd_chroot(
+                'zypper --non-interactive remove %s' % " ".join(package_names))
+        except Exception:
+            self._event_manager.progress_update(
+                "Error occured while uninstalling packages. Ignoring")
+            LOG.warn(
+                "Error occured while uninstalling packages. Ignoring. "
+                "Exception:\n%s", utils.get_exception_details())