new boot_state 'upgrade' is recognized much like 'reinstall'
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 24 Apr 2015 15:15:27 +0000 (17:15 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 24 Apr 2015 15:15:27 +0000 (17:15 +0200)
in this first rough implementation, a node in 'upgrade' mode goes through almost exactly the same steps as 'reinstall'  except for re-partitioning
one possible drawback of this approach is we might en up with too much stuff in /
that is to say we might need to clean up manually some areas of the system to avoid accumulating things from previous releases

source/BootManager.py
source/steps/InstallBootstrapFS.py
source/steps/InstallWriteConfig.py

index fd5c06f..2857d9d 100755 (executable)
@@ -163,10 +163,11 @@ class BootManager:
     # file containing initial variables/constants
 
     # the set of valid node run states
-    NodeRunStates = {'reinstall':None,
-                     'boot':None,
-                     'safeboot':None,
-                     'disabled':None,
+    NodeRunStates = {'reinstall' : None,
+                     'upgrade' : None,
+                     'boot' : None,
+                     'safeboot' : None,
+                     'disabled' : None,
                      }
     
     def __init__(self, log, forceState):
@@ -257,7 +258,7 @@ class BootManager:
             else:
                 _nodeNotInstalled()
 
-        def _reinstallRun():
+        def _reinstallRun(upgrade=False):
 
             # starting the fallback/debug ssh daemon for safety:
             # if the node install somehow hangs, or if it simply takes ages, 
@@ -276,8 +277,9 @@ class BootManager:
                 raise BootManagerException, "Hardware requirements not met."
 
             # runinstaller
-            InstallPartitionDisks.Run( self.VARS, self.LOG )            
             InstallInit.Run(self.VARS, self.LOG)                    
+            if not upgrade:
+                InstallPartitionDisks.Run(self.VARS, self.LOG)            
             InstallBootstrapFS.Run(self.VARS, self.LOG)            
             InstallWriteConfig.Run(self.VARS, self.LOG)
             InstallUninitHardware.Run(self.VARS, self.LOG)
@@ -315,7 +317,8 @@ class BootManager:
             _debugRun()
 
         # setup state -> function hash table
-        BootManager.NodeRunStates['reinstall']  = _reinstallRun
+        BootManager.NodeRunStates['reinstall']  = lambda : _reinstallRun(upgrade=False)
+        BootManager.NodeRunStates['upgrade']    = lambda : _reinstallRun(upgrade=True)
         BootManager.NodeRunStates['boot']       = _bootRun
         BootManager.NodeRunStates['safeboot']   = lambda : _debugRun('safeboot')
         BootManager.NodeRunStates['disabled']   = lambda : _debugRun('disabled')
@@ -334,7 +337,7 @@ class BootManager:
                 self.VARS['BOOT_STATE'] = self.forceState
                 UpdateBootStateWithPLC.Run(self.VARS, self.LOG)
 
-            stateRun = BootManager.NodeRunStates.get(self.VARS['BOOT_STATE'],_badstateRun)
+            stateRun = BootManager.NodeRunStates.get(self.VARS['BOOT_STATE'], _badstateRun)
             stateRun()
             success = 1
 
index db502ac..e43d824 100644 (file)
@@ -179,20 +179,26 @@ def Run(vars, log):
     log.write("Copying boot server certificates and public key\n")
 
     if os.path.exists("/usr/boot"):
-        utils.makedirs(SYSIMG_PATH + "/usr")
-        shutil.copytree("/usr/boot", SYSIMG_PATH + "/usr/boot")
+        # do nothing in case of upgrade
+        if not os.path.exists(SYSIMG_PATH + "/usr/boot"):
+            utils.makedirs(SYSIMG_PATH + "/usr")
+            shutil.copytree("/usr/boot", SYSIMG_PATH + "/usr/boot")
     elif os.path.exists("/usr/bootme"):
-        utils.makedirs(SYSIMG_PATH + "/usr/boot")
-        boot_server = file("/usr/bootme/BOOTSERVER").readline().strip()
-        shutil.copy("/usr/bootme/cacert/" + boot_server + "/cacert.pem",
-                    SYSIMG_PATH + "/usr/boot/cacert.pem")
-        file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
-        shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
+        # do nothing in case of upgrade
+        if not os.path.exists(SYSIMG_PATH + "/usr/bootme"):
+            utils.makedirs(SYSIMG_PATH + "/usr/boot")
+            boot_server = file("/usr/bootme/BOOTSERVER").readline().strip()
+            shutil.copy("/usr/bootme/cacert/" + boot_server + "/cacert.pem",
+                        SYSIMG_PATH + "/usr/boot/cacert.pem")
+            file(SYSIMG_PATH + "/usr/boot/boot_server", "w").write(boot_server)
+            shutil.copy("/usr/bootme/pubring.gpg", SYSIMG_PATH + "/usr/boot/pubring.gpg")
         
     # For backward compatibility
     if os.path.exists("/usr/bootme"):
-        utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
-        shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
+        # do nothing in case of upgrade
+        if not os.path.exists(SYSIMG_PATH + "/mnt/cdrom/bootme"):
+            utils.makedirs(SYSIMG_PATH + "/mnt/cdrom")
+            shutil.copytree("/usr/bootme", SYSIMG_PATH + "/mnt/cdrom/bootme")
 
     # ONE_PARTITION => new distribution type
     if (vars['ONE_PARTITION'] != '1'):
index 7e4d05b..276e98b 100644 (file)
@@ -7,7 +7,8 @@
 # All rights reserved.
 # expected /proc/partitions format
 
-import os, string
+import os
+import os.path
 
 from Exceptions import *
 import utils
@@ -128,28 +129,23 @@ def Run(vars, log):
     ver.write("{}\n".format(VERSION))
     ver.close()
 
+    # for upgrades : do not overwrite already existing keys 
     log.write("Creating ssh host keys\n")
     key_gen_prog = "/usr/bin/ssh-keygen"
 
-    log.write("Generating SSH1 RSA host key:\n")
-    key_file = "/etc/ssh/ssh_host_key"
-    utils.sysexec_chroot(SYSIMG_PATH, "{} -q -t rsa1 -f {} -C '' -N ''"\
-                         .format(key_gen_prog, key_file), log)
-    utils.sysexec("chmod 600 {}/{}".format(SYSIMG_PATH, key_file), log)
-    utils.sysexec("chmod 644 {}/{}.pub".format(SYSIMG_PATH, key_file), log)
-    
-    log.write("Generating SSH2 RSA host key:\n")
-    key_file = "/etc/ssh/ssh_host_rsa_key"
-    utils.sysexec_chroot(SYSIMG_PATH, "{} -q -t rsa -f {} -C '' -N ''"\
-                         .format(key_gen_prog, key_file), log)
-    utils.sysexec("chmod 600 {}/{}".format(SYSIMG_PATH, key_file), log)
-    utils.sysexec("chmod 644 {}/{}.pub".format(SYSIMG_PATH, key_file), log)
-    
-    log.write("Generating SSH2 DSA host key:\n")
-    key_file = "/etc/ssh/ssh_host_dsa_key"
-    utils.sysexec_chroot(SYSIMG_PATH, "{} -q -t dsa -f {} -C '' -N ''"\
-                         .format(key_gen_prog,key_file), log)
-    utils.sysexec("chmod 600 {}/{}".format(SYSIMG_PATH,key_file), log)
-    utils.sysexec("chmod 644 {}/{}.pub".format(SYSIMG_PATH, key_file), log)
+    key_specs = [
+        ("/etc/ssh/ssh_host_key",     'rsa1', "SSH1 RSA"),
+        ("/etc/ssh/ssh_host_rsa_key", 'rsa',  "SSH2 RSA"),
+        ("/etc/ssh/ssh_host_dsa_key", 'dsa',  "SSH2 DSA"),
+    ]
+
+    for key_file, key_type, label in key_specs:
+        abs_file = "{}/{}".format(SYSIMG_PATH, key_file)
+        if not os.path.exists(abs_file):
+            log.write("Generating {} host key {}\n".format(label, key_file))
+            utils.sysexec_chroot(SYSIMG_PATH, "{} -q -t rsa1 -f {} -C '' -N ''"\
+                                 .format(key_gen_prog, key_file), log)
+            utils.sysexec("chmod 600 {}/{}".format(SYSIMG_PATH, key_file), log)
+            utils.sysexec("chmod 644 {}/{}.pub".format(SYSIMG_PATH, key_file), log)
 
     return 1