svn merge -c 9766 https://svn.planet-lab.org/svn/BootManager/branches/3.2 into trunk
[bootmanager.git] / source / steps / InstallBootstrapFS.py
index fee0f57..72cfe16 100644 (file)
@@ -10,6 +10,7 @@
 import os, sys, string
 import popen2
 import shutil
+import traceback 
 
 from Exceptions import *
 import utils
@@ -91,41 +92,79 @@ def Run( vars, log ):
     vars['ROOT_MOUNTED']= 1
 
     # which extensions are we part of ?
-    utils.breakpoint("Getting the extension tag on node")
+    utils.breakpoint("Checking for the extension(s) tags")
+    extensions = []
     try:
-        extension_tag = BootAPI.call_api_function(vars, "GetNodeExtensions", ([NODE_ID]))
-        extensions = extension_tag.split()
+        extension_tag = BootAPI.call_api_function(vars, "GetNodeExtensions", (NODE_ID,) )
+        if extension_tag:
+            extensions = extension_tag.split()
 
     except:
-        log.write("WARNING : Failed to query tag 'extensions' - installing only core software\n")
-        extensions = []
+        log.write("WARNING : Failed to query tag 'extensions'\n")
+        log.write(traceback.format_exc())
+
+    if not extensions:
+        log.write("installing only core software\n")
     
     # check if the plain-bootstrapfs tag is set
     download_suffix=".tar.bz2"
     untar_option="-j"
     try:
-        if BootAPI.call_api_function (vars, "GetNodePlainBootstrapfs", ([NODE_ID])):
+        if BootAPI.call_api_function (vars, "GetNodePlainBootstrapfs", (NODE_ID,) ):
             download_suffix=".tar"
             untar_option=""
     except:
-        pass
+        log.write("WARNING : Failed to query tag 'plain-bootstrapfs'\n")
+        log.write(traceback.format_exc())
+
+    if not untar_option:
+        log.write("Using uncompressed bootstrapfs images\n")
 
     # see also GetBootMedium in PLCAPI that does similar things
     # figuring the default node family:
-    # (1) look at /etc/planetlab/nodefamily on the bootcd
-    # (2) if that fails, set to planetlab-i386
+    # (1) get node's tags 'arch' and 'pldistro'
+    # (2) if unsuccessful search /etc/planetlab/nodefamily on the bootcd
+    # (3) if that fails, set to planetlab-i386
+
+    try:
+        api_pldistro = BootAPI.call_api_function(vars, "GetNodePldistro", (NODE_ID,) )
+    except:
+        log.write("WARNING : Failed to query tag 'pldistro'\n")
+        api_pldistro = None
+    try:
+        api_arch = BootAPI.call_api_function(vars, "GetNodeArch", (NODE_ID,) )
+    except:
+        log.write("WARNING : Failed to query tag 'arch'\n")
+        api_arch = None
     try:
-        (pldistro,arch) = file("/etc/planetlab/nodefamily").read().strip().split("-")
+        (etc_pldistro,etc_arch) = file("/etc/planetlab/nodefamily").read().strip().split("-")
     except:
-        # what arch should be used for this node
-        utils.breakpoint("Getting the arch tag on node")
-        pldistro="planetlab"
-        default_arch="i386"
-        try:
-            arch = BootAPI.call_api_function(vars, "GetNodeArch", ([NODE_ID]))
-        except:
-            log.write("WARNING : Failed to query node arch - using %(default_arch)s\n"%locals())
-            arch = default_arch
+        log.write("WARNING : Failed to parse /etc/planetlab/nodefamily\n")
+        (etc_pldistro,etc_arch)=(None,None)
+    default_pldistro="planetlab"
+    default_arch="i386"
+
+    if api_pldistro:
+        pldistro = api_pldistro
+        log.write ("Using pldistro from pldistro API tag\n")
+    elif etc_pldistro:
+        pldistro = etc_pldistro
+        log.write ("Using pldistro from /etc/planetlab/nodefamily\n")
+    else:
+        pldistro = default_pldistro
+        log.write ("Using default pldistro\n")
+
+    if api_arch:
+        arch = api_arch
+        log.write ("Using arch from arch API tag\n")
+    elif etc_arch:
+        arch = etc_arch
+        log.write ("Using arch from /etc/planetlab/nodefamily\n")
+    else:
+        arch = default_arch
+        log.write ("Using default arch\n")
+
+    log.write ("Using nodefamily=%s-%s\n"%(pldistro,arch))
 
     bootstrapfs_names = [ pldistro ] + extensions
 
@@ -190,13 +229,12 @@ def Run( vars, log ):
     utils.sysexec("gpg --homedir=/root --export --armor" \
                   " --no-default-keyring --keyring %s/usr/boot/pubring.gpg" \
                   " >%s/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % (SYSIMG_PATH, SYSIMG_PATH))
-    utils.sysexec("chroot %s rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % \
-                  SYSIMG_PATH)
+    utils.sysexec_chroot(SYSIMG_PATH, "rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab")
 
     # the yum config has changed entirely; 
     # in addition yum installs have more or less never worked - let's forget about this
     # maybe NodeManager could profitably do the job instead
     if yum_extensions:
-        log.write('WARNING : yum installs for node extensions are not supported anymore')
+        log.write("WARNING : yum installs for node extensions are not supported anymore\n")
 
     return 1