X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=source%2Fsteps%2FInstallBootstrapFS.py;h=83de63099b05c8d1b2d76a578f7321244bd478ea;hb=eb4cc94dcb8512246c6b35d59c9b425f48ae6387;hp=83298fe42f3e7b93410e5345c1788d15409d3dd1;hpb=fe094f10f0d738ab448780c3d5816717b7c54fc7;p=bootmanager.git diff --git a/source/steps/InstallBootstrapFS.py b/source/steps/InstallBootstrapFS.py index 83298fe..83de630 100644 --- a/source/steps/InstallBootstrapFS.py +++ b/source/steps/InstallBootstrapFS.py @@ -1,5 +1,5 @@ #!/usr/bin/python - +# # Copyright (c) 2003 Intel Corporation # All rights reserved. # @@ -11,6 +11,7 @@ import os, sys, string import popen2 import shutil import traceback +import time from Exceptions import * import utils @@ -20,8 +21,7 @@ import BootAPI def Run( vars, log ): """ - Download enough files to run rpm and yum from a chroot in - the system image directory + Download core + extensions bootstrapfs tarballs and install on the hard drive Expect the following variables from the store: SYSIMG_PATH the path where the system image will be mounted @@ -52,6 +52,8 @@ def Run( vars, log ): if NODE_ID == "": raise ValueError, "NODE_ID" + VERSION=vars['VERSION'] or 'unknown' + except KeyError, var: raise BootManagerException, "Missing variable in vars: %s\n" % var except ValueError, var: @@ -85,124 +87,82 @@ 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("Checking for the extension(s) tags") - extensions = [] + # call getNodeFlavour try: - extension_tag = BootAPI.call_api_function(vars, "GetNodeExtensions", (NODE_ID,) ) - if extension_tag: - extensions = extension_tag.split() - + node_flavour = BootAPI.call_api_function(vars, "GetNodeFlavour", (NODE_ID,) ) + nodefamily = node_flavour['nodefamily'] + extensions = node_flavour['extensions'] + plain = node_flavour['plain'] except: - log.write("WARNING : Failed to query tag 'extensions'\n") - log.write(traceback.format_exc()) - - if not extensions: - log.write("installing only core software\n") + exc_type, exc_value, exc_traceback = sys.exc_info() + lines=traceback.format_exception(exc_type,exc_value,exc_traceback) + for line in lines: log.write(line) + raise BootManagerException ("Could not call GetNodeFlavour - need PLCAPI-5.0") - # 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,) ): - download_suffix=".tar" - untar_option="" - except: - 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) 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: - (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") + log.write ("Retrieved 'virt' style %s from GetNodeFlavour\n"%node_flavour['virt']) + # the 'plain' option is for tests mostly + if plain: + download_suffix=".tar" + uncompress_option="" + log.write("Using plain bootstrapfs images\n") else: - arch = default_arch - log.write ("Using default arch\n") - - log.write ("Using nodefamily=%s-%s\n"%(pldistro,arch)) + download_suffix=".tar.bz2" + uncompress_option="-j" + log.write("Using compressed bootstrapfs images\n") - # deployment has no arch nor extensions, let operators put what they want in there - if deployment: - bootstrapfs_names = [ deployment ] + log.write ("Using nodefamily=%s\n"%(nodefamily)) + if not extensions: + log.write("Installing only core software\n") 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 + log.write("Requested extensions %r\n" % extensions) + + bootstrapfs_names = [ nodefamily ] + extensions - # installing extensions through yum has been dismantled - yum_extensions = [] - # download and extract support tarball for this step, for name in bootstrapfs_names: tarball = "bootstrapfs-%s%s"%(name,download_suffix) - source_file= "/boot/%s" % (SUPPORT_FILE_DIR,tarball) + source_file= "/boot/%s" % (tarball) dest_file= "%s/%s" % (SYSIMG_PATH, tarball) + source_hash_file= "/boot/%s.sha1sum" % (tarball) + dest_hash_file= "%s/%s.sha1sum" % (SYSIMG_PATH, tarball) + + time_beg=time.time() + log.write( "downloading %s\n" % source_file ) # 30 is the connect timeout, 14400 is the max transfer time in # seconds (4 hours) - log.write( "downloading %s\n" % source_file ) - result= bs_request.DownloadFile( source_file, None, None, + result = bs_request.DownloadFile( source_file, None, None, 1, 1, dest_file, 30, 14400) + time_end=time.time() + duration=int(time_end-time_beg) + log.write("Done downloading (%s seconds)\n"%duration) if result: + # Download SHA1 checksum file + log.write( "downloading sha1sum for %s\n"%source_file) + result = bs_request.DownloadFile( source_hash_file, None, None, + 1, 1, dest_hash_file, + 30, 14400) + + log.write( "verifying sha1sum for %s\n"%source_file) + if not utils.check_file_hash(dest_file, dest_hash_file): + raise BootManagerException, "FATAL: SHA1 checksum does not match between %s and %s" % (source_file, source_hash_file) + + + time_beg=time.time() log.write( "extracting %s in %s\n" % (dest_file,SYSIMG_PATH) ) - result= utils.sysexec( "tar -C %s -xpf %s %s" % (SYSIMG_PATH,dest_file,untar_option), log ) - log.write( "Done\n") + result = utils.sysexec( "tar -C %s -xpf %s %s" % (SYSIMG_PATH,dest_file,uncompress_option), log ) + time_end=time.time() + duration=int(time_end-time_beg) + log.write( "Done extracting (%s seconds)\n"%duration) utils.removefile( dest_file ) else: # the main tarball is required - if name == "%s-%s"%(pldistro,arch): - raise BootManagerException, "Unable to download main tarball %s from server." % \ + if name == nodefamily: + raise BootManagerException, "FATAL: Unable to download main tarball %s from server." % \ source_file + # for extensions, just print a warning else: - log.write("tarball for %s not found, scheduling a yum attempt\n"%(name)) - yum_extensions.append(name) + log.write("WARNING: tarball for extension %s not found\n"%(name)) # copy resolv.conf from the base system into our temp dir # so DNS lookups work correctly while we are chrooted @@ -233,13 +193,15 @@ def Run( vars, log ): utils.makedirs(SYSIMG_PATH + "/etc/pki/rpm-gpg") 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(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\n") + " >%s/etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab" % (SYSIMG_PATH, SYSIMG_PATH), log) + utils.sysexec_chroot(SYSIMG_PATH, "rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-planetlab", log) + + # keep a log on the installed hdd + stamp=file(SYSIMG_PATH + "/bm-install.txt",'w') + now=time.strftime("%Y-%b-%d @ %H:%M %Z", time.gmtime()) + stamp.write("Hard drive installed by BootManager %s\n"%VERSION) + stamp.write("Finished extraction of bootstrapfs on %s\n"%now) + stamp.write("Using nodefamily %s\n"%nodefamily) + stamp.close() return 1