Przeglądaj źródła

Skip faulty offline disks during Windows OSMount.

In some situations the Windows worker VMs may have non-migrated disks
attached which they cannot bring online (ex: the config drive or
hypervisort-default floppy drive).
Coriolis should try to ignore disks which cannot be brought online, as
there is a good chance that it's not the OS disk and thus the OSMorphing
process should complete successfully.
Nashwan Azhari 8 lat temu
rodzic
commit
d32abea20b
1 zmienionych plików z 26 dodań i 5 usunięć
  1. 26 5
      coriolis/osmorphing/osmount/windows.py

+ 26 - 5
coriolis/osmorphing/osmount/windows.py

@@ -73,7 +73,7 @@ class WindowsMountTools(base.BaseOSMountTools):
         return self._conn.exec_ps_command("diskpart.exe /s '%s'" % filepath)
         return self._conn.exec_ps_command("diskpart.exe /s '%s'" % filepath)
 
 
     def _service_disks_with_status(
     def _service_disks_with_status(
-            self, status, service_script_with_id_fmt,
+            self, status, service_script_with_id_fmt, skip_on_error=False,
             logmsg_fmt="Operating on disk with index '%s'"):
             logmsg_fmt="Operating on disk with index '%s'"):
         """Executes given service script on detected disks.
         """Executes given service script on detected disks.
 
 
@@ -92,15 +92,32 @@ class WindowsMountTools(base.BaseOSMountTools):
         servicable_disk_ids = [m.group(1) for m in [
         servicable_disk_ids = [m.group(1) for m in [
             re.match(search_disk_entry_re, l) for l in disk_list.split("\r\n")]
             re.match(search_disk_entry_re, l) for l in disk_list.split("\r\n")]
             if m is not None]
             if m is not None]
+        LOG.debug(
+            "Servicing disks with status '%s' (%s) from disk list: %s",
+            status, servicable_disk_ids, disk_list)
         for disk_id in servicable_disk_ids:
         for disk_id in servicable_disk_ids:
             curr_disk_entry_re = disk_entry_re % (disk_id, status)
             curr_disk_entry_re = disk_entry_re % (disk_id, status)
 
 
-            disk_list = self._run_diskpart_script("LIST DISK\r\nEXIT")
+            disk_list = self._run_diskpart_script(disk_list_script)
             for line in disk_list.split("\r\n"):
             for line in disk_list.split("\r\n"):
                 if re.match(curr_disk_entry_re, line):
                 if re.match(curr_disk_entry_re, line):
                     LOG.info(logmsg_fmt, disk_id)
                     LOG.info(logmsg_fmt, disk_id)
-                    self._run_diskpart_script(
-                        service_script_with_id_fmt % disk_id)
+                    script = service_script_with_id_fmt % disk_id
+                    try:
+                        self._run_diskpart_script(script)
+                    except Exception as ex:
+                        if skip_on_error:
+                            LOG.warn(
+                                "Exception ocurred while servicing disk '%s' "
+                                "with status '%s'.Skipping running script '%s'"
+                                ". Error message: %s" % (
+                                    disk_id, status, script, ex))
+                            self._event_manager.progress_update(
+                                "Exception ocurred while servicing disk '%s' "
+                                "with status '%s'. Skipping servicing disk" % (
+                                    disk_id, status))
+                        else:
+                            raise
                     break
                     break
 
 
     def _set_foreign_disks_rw_mode(self):
     def _set_foreign_disks_rw_mode(self):
@@ -131,8 +148,12 @@ class WindowsMountTools(base.BaseOSMountTools):
 
 
     def _bring_all_disks_online(self):
     def _bring_all_disks_online(self):
         online_disk_script_fmt = "SELECT DISK %s\r\nONLINE DISK\r\nEXIT"
         online_disk_script_fmt = "SELECT DISK %s\r\nONLINE DISK\r\nEXIT"
+        # NOTE (aznashwan): there is a chance that some disks on Windows
+        # worker VMs won't be able to be brought online, but they may not be
+        # the boot disk and thus can be skipped on error and still have a good
+        # chance that the OSMorphing process will complete successfully.
         self._service_disks_with_status(
         self._service_disks_with_status(
-            "Offline", online_disk_script_fmt,
+            "Offline", online_disk_script_fmt, skip_on_error=True,
             logmsg_fmt="Bringing offline disk with ID %s online.")
             logmsg_fmt="Bringing offline disk with ID %s online.")
 
 
     def _set_basic_disks_rw_mode(self):
     def _set_basic_disks_rw_mode(self):