(no commit message)
[bootmanager.git] / source / steps / InstallBootstrapFS.py
index f7e9be0..83298fe 100644 (file)
@@ -27,8 +27,6 @@ def Run( vars, log ):
     SYSIMG_PATH          the path where the system image will be mounted
     PARTITIONS           dictionary of generic part. types (root/swap)
                          and their associated devices.
-    SUPPORT_FILE_DIR     directory on the boot servers containing
-                         scripts and support files
     NODE_ID              the id of this machine
     
     Sets the following variables:
@@ -50,10 +48,6 @@ def Run( vars, log ):
         if PARTITIONS == None:
             raise ValueError, "PARTITIONS"
 
-        SUPPORT_FILE_DIR= vars["SUPPORT_FILE_DIR"]
-        if SUPPORT_FILE_DIR == None:
-            raise ValueError, "SUPPORT_FILE_DIR"
-
         NODE_ID= vars["NODE_ID"]
         if NODE_ID == "":
             raise ValueError, "NODE_ID"
@@ -73,7 +67,7 @@ def Run( vars, log ):
         log.write( "Missing partition in PARTITIONS: %s\n" % part )
         return 0   
 
-    bs_request= BootServerRequest.BootServerRequest()
+    bs_request= BootServerRequest.BootServerRequest(vars)
     
     log.write( "turning on swap space\n" )
     utils.sysexec( "swapon %s" % PARTITIONS["swap"], log )
@@ -91,8 +85,15 @@ def Run( vars, log ):
 
     vars['ROOT_MOUNTED']= 1
 
+    # fetch deployment tag (like, 'alpha' or the like)
+    try:
+        deployment = BootAPI.call_api_function(vars, "GetNodeDeployment", (NODE_ID,) )
+    except:
+        log.write("WARNING : Failed to query tag 'deployment'\n")
+        deployment = ""
+
     # 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,) )
@@ -100,7 +101,7 @@ def Run( vars, log ):
             extensions = extension_tag.split()
 
     except:
-        log.write("WARNING : Failed to query tag 'extensions'")
+        log.write("WARNING : Failed to query tag 'extensions'\n")
         log.write(traceback.format_exc())
 
     if not extensions:
@@ -114,7 +115,7 @@ def Run( vars, log ):
             download_suffix=".tar"
             untar_option=""
     except:
-        log.write("WARNING : Failed to query tag 'plain-bootstrapfs'")
+        log.write("WARNING : Failed to query tag 'plain-bootstrapfs'\n")
         log.write(traceback.format_exc())
 
     if not untar_option:
@@ -122,35 +123,65 @@ def Run( vars, log ):
 
     # 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:
-        (pldistro,arch) = file("/etc/planetlab/nodefamily").read().strip().split("-")
+        api_pldistro = BootAPI.call_api_function(vars, "GetNodePldistro", (NODE_ID,) )
     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 tag 'arch'")
-            log.write(traceback.format_exc())
-            arch = default_arch
-
-    log.write ("Using arch=%s\n"%arch)
-
-    bootstrapfs_names = [ pldistro ] + extensions
+        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:
+        (etc_pldistro,etc_arch) = file("/etc/planetlab/nodefamily").read().strip().split("-")
+    except:
+        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))
+
+    # deployment has no arch nor extensions, let operators put what they want in there
+    if deployment:
+        bootstrapfs_names = [ deployment ]
+    else:
+        bootstrapfs_names = [ "%s-%s"%(x,arch) for x in [ pldistro ] + extensions ]
 
     # download and extract support tarball for this step, which has
     # everything we need to successfully run
 
-    # we first try to find a tarball, if it is not found we use yum instead
+    # installing extensions through yum has been dismantled
     yum_extensions = []
     # download and extract support tarball for this step, 
-    for bootstrapfs_name in bootstrapfs_names:
-        tarball = "bootstrapfs-%s-%s%s"%(bootstrapfs_name,arch,download_suffix)
-        source_file= "%s/%s" % (SUPPORT_FILE_DIR,tarball)
+    for name in bootstrapfs_names:
+        tarball = "bootstrapfs-%s%s"%(name,download_suffix)
+        source_file= "/boot/%s" % (SUPPORT_FILE_DIR,tarball)
         dest_file= "%s/%s" % (SYSIMG_PATH, tarball)
 
         # 30 is the connect timeout, 14400 is the max transfer time in
@@ -166,12 +197,12 @@ def Run( vars, log ):
             utils.removefile( dest_file )
         else:
             # the main tarball is required
-            if bootstrapfs_name == pldistro:
+            if name == "%s-%s"%(pldistro,arch):
                 raise BootManagerException, "Unable to download main tarball %s from server." % \
                     source_file
             else:
-                log.write("tarball for %s-%s not found, scheduling a yum attempt\n"%(bootstrapfs_name,arch))
-                yum_extensions.append(bootstrapfs_name)
+                log.write("tarball for %s not found, scheduling a yum attempt\n"%(name))
+                yum_extensions.append(name)
 
     # copy resolv.conf from the base system into our temp dir
     # so DNS lookups work correctly while we are chrooted
@@ -203,13 +234,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