[node-patches] Change in ovirt-node[master]: fix iscsi upgrade both online and from install media

jboggs at redhat.com jboggs at redhat.com
Mon Dec 17 18:55:29 UTC 2012


Joey Boggs has uploaded a new change for review.

Change subject: fix iscsi upgrade both online and from install media
......................................................................

fix iscsi upgrade both online and from install media

rhbz#885987

Change-Id: I12ab54ce821d5727d7a0d6efa06009276215055b
Signed-off-by: Joey Boggs <jboggs at redhat.com>
---
M scripts/ovirtnode/install.py
M scripts/ovirtnode/ovirtfunctions.py
2 files changed, 119 insertions(+), 56 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/73/10173/1

diff --git a/scripts/ovirtnode/install.py b/scripts/ovirtnode/install.py
index b825ac3..cf71495 100755
--- a/scripts/ovirtnode/install.py
+++ b/scripts/ovirtnode/install.py
@@ -153,12 +153,20 @@
             partB = 1
             if self.partN == 1:
                 partB = 2
+            if _functions.is_iscsi_install():
+                partB = 0
+                if self.partN == 0:
+                    partB = 1
             self.grub_dict['oldtitle'] = self.oldtitle
             self.grub_dict['partB'] = partB
             grub_conf.write(GRUB_BACKUP_TEMPLATE % self.grub_dict)
         grub_conf.close()
-        # splashscreen
-        _functions.system("cp /live/EFI/BOOT/splash.xpm.gz /liveos/grub")
+        # usb devices requires default BOOTX64 entries
+        _functions.system("mkdir -p /liveos/efi/EFI/BOOT")
+        _functions.system("cp /boot/efi/EFI/redhat/grub.efi /liveos/efi/EFI/BOOT/BOOTX64.efi")
+        _functions.system("cp /liveos/efi/EFI/redhat/grub.conf /liveos/efi/EFI/BOOT/BOOTX64.conf")
+        _functions.system("umount /liveos/efi")
+        _functions.system("cp /live/EFI/BOOT/splash.xpm.gz %s" % self.grub_dir)
         if not _functions.is_efi_boot():
             for f in ["stage1", "stage2", "e2fs_stage1_5"]:
                 _functions.system("cp /usr/share/grub/x86_64-redhat/%s %s" % \
@@ -267,14 +275,18 @@
                 grub_config_file = self.grub_config_file
 
         elif not _functions.is_firstboot():
-            if os.path.ismount("/dev/.initramfs/live"):
+            # find existing iscsi install
+            if _functions.findfs("Boot"):
+                grub_config_file = "/boot/grub/grub.conf"
+            elif os.path.ismount("/dev/.initramfs/live"):
                 grub_config_file = "/dev/.initramfs/live/grub/grub.conf"
             elif os.path.ismount("/run/initramfs/live"):
                 grub_config_file = "/run/initramfs/live/grub/grub.conf"
-            if is_upgrade():
+            if is_upgrade() and not _functions.is_iscsi_install():
                 mount_liveos()
                 grub_config_file = "/liveos/grub/grub.conf"
-
+        if _functions.is_iscsi_install():
+            grub_config_file = "/boot/grub/grub.conf"
         if not grub_config_file is None and os.path.exists(grub_config_file):
             f=open(grub_config_file)
             oldgrub=f.read()
@@ -288,35 +300,29 @@
             self.boot_candidate = "BootBackup"
         elif _functions.findfs("Boot"):
             self.boot_candidate = "Boot"
-            if not os.path.ismount("/boot"):
-                logger.error("Boot partition not available, Install Failed")
-                return False
-            # Grab OVIRT_ISCSI VARIABLES from boot partition for upgrading
-            # file created only if OVIRT_ISCSI_ENABLED=y
-            if os.path.exists("/boot/ovirt"):
-                try:
-                    f = open("/boot/ovirt", 'r')
-                    for line in f:
-                        try:
-                            line = line.strip()
-                            key, value = line.split("\"", 1)
-                            key = key.strip("=")
-                            key = key.strip()
-                            value = value.strip("\"")
+        # Grab OVIRT_ISCSI VARIABLES from boot partition for upgrading
+        # file created only if OVIRT_ISCSI_ENABLED=y
+        if os.path.exists("/boot/ovirt"):
+            try:
+                f = open("/boot/ovirt", 'r')
+                for line in f:
+                    try:
+                        line = line.strip()
+                        key, value = line.split("\"", 1)
+                        key = key.strip("=")
+                        key = key.strip()
+                        value = value.strip("\"")
+                        if not "FIRSTBOOT" in key and not "INSTALL" in key:
+                            augtool("set", "/files/" + OVIRT_DEFAULTS + "/"+ key, '"' +value + '"')
                             OVIRT_VARS[key] = value
-                        except:
-                            pass
-                    f.close()
-                    iscsiadm_cmd = (("iscsiadm -p %s:%s -m discovery -t " +
-                                     "sendtargets") % (
-                                        OVIRT_VARS["OVIRT_ISCSI_TARGET_IP"],
-                                        OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
-                    _functions.system(iscsiadm_cmd)
-                    logger.info("Restarting iscsi service")
-                    _functions.system("service iscsi restart")
-                except:
-                    pass
-        if _functions.findfs("RootBackup"):
+                    except:
+                        pass
+                f.close()
+            except:
+                pass
+            finally:
+                _functions.system("umount /boot")
+        if findfs("RootBackup"):
             candidate = "RootBackup"
         elif _functions.findfs("RootUpdate"):
             candidate = "RootUpdate"
@@ -335,7 +341,7 @@
         logger.debug("candidate: " + candidate)
 
         if _functions.is_iscsi_install():
-            _functions.system("mount LABEL=%s /boot" % self.boot_candidate)
+            _functions.system("mount LABEL=%s /boot &>/dev/null" % self.boot_candidate)
         try:
             candidate_dev = self.disk = _functions.findfs(candidate)
             logger.info(candidate_dev)
@@ -513,11 +519,18 @@
             logger.error("Unable to relabel " + candidate_dev +
                          " to RootUpdate ")
             return False
-        _functions.disable_firstboot()
-        if _functions.finish_install():
-            _iscsi.iscsi_auto()
-            logger.info("Installation of %s Completed" % \
-                                                      _functions.PRODUCT_SHORT)
+        if _functions.is_iscsi_install():
+            e2label_cmd = "e2label \"%s\" BootUpdate" \
+                % _functions.findfs(self.boot_candidate)
+            if not _functions.system(e2label_cmd):
+                logger.error("Unable to relabel " + \
+                    _functions.findfs(self.boot_candidate) + " to RootUpdate ")
+                return False
+
+        disable_firstboot()
+        if finish_install():
+            iscsi_auto()
+            logger.info("Installation of %s Completed" % PRODUCT_SHORT)
             if reboot is not None and reboot == "Y":
                 f = open('/var/spool/cron/root', 'w')
                 f.write('* * * * * sleep 10 && /sbin/reboot\n')
diff --git a/scripts/ovirtnode/ovirtfunctions.py b/scripts/ovirtnode/ovirtfunctions.py
index 0274330..59cbf12 100644
--- a/scripts/ovirtnode/ovirtfunctions.py
+++ b/scripts/ovirtnode/ovirtfunctions.py
@@ -246,6 +246,12 @@
     else:
         return False
 
+def is_install():
+    if OVIRT_VARS.has_key("OVIRT_INSTALL") and OVIRT_VARS["OVIRT_INSTALL"] == "1":
+        return True
+    else:
+        return False
+
 # return 0 if booted from local disk
 # return 1 if booted from other media
 def is_booted_from_local_disk():
@@ -340,6 +346,7 @@
 def disable_firstboot():
     if os.path.ismount("/config"):
         aug.set("/files/etc/default/ovirt/OVIRT_FIRSTBOOT", "0")
+        aug.set("/files/etc/default/ovirt/OVIRT_INSTALL", "0")
         aug.set("/files/etc/default/ovirt/OVIRT_INIT", '""')
         aug.set("/files/etc/default/ovirt/OVIRT_UPGRADE", "0")
         aug.save()
@@ -485,8 +492,10 @@
     if os.path.ismount("/liveos"):
         return True
     else:
+        if is_iscsi_install():
+            connect_iscsi_root()
         system_closefds("mkdir -p /liveos")
-        if not system("mount LABEL=Root /liveos"):
+        if not system("mount LABEL=Root /liveos &>/dev/null"):
             # just in case /dev/disk/by-label is not using devmapper and fails
             for dev in os.listdir("/dev/mapper"):
                 if system("e2label \"/dev/mapper/" + dev + "\" 2>/dev/null|grep Root|grep -v Backup"):
@@ -544,12 +553,43 @@
         # /config is not available
         return False
 
-def mount_boot(self):
-    if os.path.ismount("/boot"):
-        return
-    else:
-        system_closefds("mkdir -p /boot")
-        system_closefds("mount LABEL=Boot /boot")
+def mount_boot():
+    system_closefds("mkdir -p /boot")
+    system_closefds("mount LABEL=Boot /boot &>/dev/null")
+
+def connect_iscsi_root():
+    mount_boot()
+    if os.path.exists("/boot/ovirt"):
+        try:
+            f = open("/boot/ovirt", 'r')
+            for line in f:
+                try:
+                    line = line.strip()
+                    key, value = line.split("\"", 1)
+                    key = key.strip("=")
+                    key = key.strip()
+                    value = value.strip("\"")
+                    if not "FIRSTBOOT" in key and not "INSTALL" in key:
+                        OVIRT_VARS[key] = value
+                except:
+                    pass
+            f.close()
+            if is_firstboot() or is_upgrade() or is_install() \
+                or not is_booted_from_local_disk():
+                iscsiadm_cmd = (("iscsiadm -p %s:%s -m discovery -t " +
+                                 "sendtargets") % (
+                                 OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
+                                 OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
+                system(iscsiadm_cmd)
+                login_cmd = ("iscsiadm -m node -T %s -p %s:%s -l" %
+                            (OVIRT_VARS["OVIRT_ISCSI_TARGET_NAME"],
+                            OVIRT_VARS["OVIRT_ISCSI_TARGET_HOST"],
+                            OVIRT_VARS["OVIRT_ISCSI_TARGET_PORT"]))
+                system(login_cmd)
+                logger.info("Restarting iscsi service")
+                system("service iscsi restart")
+        except:
+            logger.info("Unable to connect to iscsi root")
 
 # stop any service which keeps /var/log busy
 # keep the list of services
@@ -912,16 +952,24 @@
 
 def finish_install():
     logger.info("Completing Installation")
-    if not OVIRT_VARS.has_key("OVIRT_ISCSI_ENABLED"):
-        # setup new Root if update is prepared
-        root_update_dev = findfs("RootUpdate")
-        root_dev = findfs("Root")
-        e2label_rootbackup_cmd = "e2label '%s' RootBackup" % root_dev
-        e2label_root_cmd = "e2label '%s' Root" % root_update_dev
-        logger.debug(e2label_rootbackup_cmd)
-        logger.debug(e2label_root_cmd)
-        subprocess_closefds(e2label_rootbackup_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
-        subprocess_closefds(e2label_root_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+    root_update_dev = findfs("RootUpdate")
+    root_dev = findfs("Root")
+    e2label_rootbackup_cmd = "e2label '%s' RootBackup" % root_dev
+    e2label_root_cmd = "e2label '%s' Root" % root_update_dev
+    logger.debug(e2label_rootbackup_cmd)
+    logger.debug(e2label_root_cmd)
+    subprocess_closefds(e2label_rootbackup_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+    subprocess_closefds(e2label_root_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+
+    if is_iscsi_install():
+        boot_update_dev = findfs("BootUpdate")
+        boot_dev = findfs("Boot")
+        e2label_bootbackup_cmd = "e2label '%s' BootBackup" % boot_dev
+        e2label_boot_cmd = "e2label '%s' Boot" % boot_update_dev
+        logger.debug(e2label_bootbackup_cmd)
+        logger.debug(e2label_boot_cmd)
+        subprocess_closefds(e2label_bootbackup_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
+        subprocess_closefds(e2label_boot_cmd, shell=True, stdout=PIPE, stderr=STDOUT)
     # run post-install hooks
     # e.g. to avoid reboot loops using Cobbler PXE only once
     # Cobbler XMLRPC post-install trigger (XXX is there cobbler SRV record?):
@@ -1495,6 +1543,8 @@
 def is_iscsi_install():
     if OVIRT_VARS.has_key("OVIRT_ISCSI_INSTALL") and OVIRT_VARS["OVIRT_ISCSI_INSTALL"].upper() == "Y":
         return True
+    elif findfs("Boot"):
+        return True
     else:
         return False
 


--
To view, visit http://gerrit.ovirt.org/10173
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I12ab54ce821d5727d7a0d6efa06009276215055b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Joey Boggs <jboggs at redhat.com>



More information about the node-patches mailing list