def do_upgrade(self, forced=False): fit_image = None for f in sysconfig.upgrade.loader.package.fit: fp = os.path.join(sysconfig.upgrade.loader.package.dir, f) if os.path.exists(fp): fit_image = fp; break if fit_image is None: self.abort("The FIT upgrade image is missing. Upgrade cannot continue.") with OnlMountContextReadWrite("ONL-BOOT", self.logger) as d: self.copyfile(fit_image, os.path.join(d.directory, "%s.itb" % (self.platform.platform()))) onlPlatform = onl.platform.current.OnlPlatform() with OnieBootContext(log=self.logger) as octx: if os.path.exists("/usr/bin/onie-shell"): machineConf = OnieSysinfo(log=self.logger.getChild("onie-sysinfo")) else: path = os.path.join(octx.initrdDir, "etc/machine.conf") if os.path.exists(path): machineConf = ConfUtils.MachineConf(path=path) else: machineConf = ConfUtils.MachineConf(path='/dev/null') installerConf = ConfUtils.InstallerConf(path="/dev/null") # start with an empty installerConf, fill it in piece by piece installerConf.installer_platform = onlPlatform.platform() installerConf.installer_arch = machineConf.onie_arch installerConf.installer_platform_dir = os.path.join("/lib/platform-config", onlPlatform.platform()) mfPath = os.path.join(sysconfig.upgrade.loader.package.dir, "manifest.json") mf = onl.versions.OnlVersionManifest(mfPath) installerConf.onl_version = mf.RELEASE_ID grubEnv = ConfUtils.ProxyGrubEnv(installerConf, bootDir="/mnt/onie-boot", path="/grub/grubenv", chroot=False, log=self.logger.getChild("grub")) ubootEnv = ConfUtils.UbootEnv(log=self.logger.getChild("u-boot")) installer = self.installer_klass(machineConf=machineConf, installerConf=installerConf, platformConf=onlPlatform.platform_config, grubEnv=grubEnv, ubootEnv=ubootEnv, force=True, log=self.logger) installer.upgradeBootLoader() installer.shutdown() self.reboot()
def _runInitrd(self, helper, path): with InitrdContext(initrd=path, log=self.log) as ctx: tdir = os.path.join(ctx.dir, "tmp") abs_idir = tempfile.mkdtemp(dir=tdir, prefix="installer-", suffix=".d") chroot_idir = abs_idir[len(ctx.dir):] with OnieBootContext(log=self.log) as octx: self.log.info("onie directory is %s", octx.onieDir) self.log.info("initrd directory is %s", octx.initrdDir) src = os.path.join(octx.initrdDir, "etc/machine.conf") dst = os.path.join(ctx.dir, "etc/machine.conf") self.log.debug("+ /bin/cp %s %s", src, dst) shutil.copy2(src, dst) src = "/etc/fw_env.config" if os.path.exists(src): dst = os.path.join(ctx.dir, "etc/fw_env.config") self.log.debug("+ /bin/cp %s %s", src, dst) shutil.copy2(src, dst) srcRoot = "/etc/onl" dstRoot = os.path.join(ctx.dir, "etc") self.cpR(srcRoot, dstRoot) # constitute an /etc/onl/installer.conf in place installerConf = InstallerConf(path="/dev/null") vj = "/etc/onl/loader/versions.json" if os.path.exists(vj): with open(vj) as fd: data = json.load(fd) installerConf.onl_version = data['VERSION_ID'] else: installerConf.onl_version = "unknown" installerConf.installer_dir = chroot_idir abs_postinst = tempfile.mktemp(dir=abs_idir, prefix="postinst-", suffix=".sh") chroot_postinst = abs_postinst[len(ctx.dir):] installerConf.installer_postinst = chroot_postinst # make an empty(ish) zip file (local path in installer_dir) for collateral zipPath = tempfile.mktemp(dir=abs_idir, prefix="install-", suffix=".zip") with zipfile.ZipFile(zipPath, "w") as zf: pass installerConf.installer_zip = os.path.split(zipPath)[1] # finalize the local installer.conf dst = os.path.join(ctx.dir, "etc/onl/installer.conf") with open(dst, "w") as fd: fd.write(installerConf.dumps()) # populate installer_dir with the contents of the loader upgrade # See also Loader_Upgrade_x86_64.do_upgrade # Here the initrd filename is as per the installer.zip; # it is renamed on install to the grub directory sdir = sysconfig.upgrade.loader.package.dir # get kernels for grub installs: pats = [ "kernel-*", ] for f in os.listdir(sdir): for pat in pats: if fnmatch.fnmatch(f, pat): src = os.path.join(sdir, f) dst = os.path.join(abs_idir, f) self.log.debug("+ /bin/cp %s %s", src, dst) shutil.copy2(src, dst) try: l = sysconfig.upgrade.loader.package.grub except AttributeError: l = [] for f in l: src = os.path.join(sdir, f) if os.path.exists(src): dst = os.path.join(abs_idir, f) self.log.debug("+ /bin/cp %s %s", src, dst) shutil.copy2(src, dst) # get FIT files from powerpc installs: try: l = sysconfig.upgrade.loader.package.fit except AttributeError: l = [] for f in l: src = os.path.join(sdir, f) if os.path.exists(src): dst = os.path.join(abs_idir, f) self.log.debug("+ /bin/cp %s %s", src, dst) shutil.copy2(src, dst) # # Disable until a system for boot-config upgrade is implemented. # with OnlMountContextReadWrite('ONL-BOOT', logger=self.log) as octx: # src = os.path.join(octx.directory, "boot-config") # dst = os.path.join(abs_idir, "boot-config") # self.log.debug("+ /bin/cp %s %s", src, dst) # shutil.copy2(src, dst) # # chroot to the onl-install script ##cmd = ('chroot', ctx.dir, ## '/bin/sh', '-i') if self.log.level < logging.INFO: cmd = ( 'chroot', ctx.dir, "/usr/bin/onl-install", "--verbose", "--force", ) else: cmd = ( 'chroot', ctx.dir, "/usr/bin/onl-install", "--force", ) try: self.check_call(cmd) except subprocess.CalledProcessError, what: pass
def do_upgrade(self, forced=False): X86_64_UPGRADE_DIR = sysconfig.upgrade.loader.package.dir X86_64_UPGRADE_KERNEL_PATTERNS = ["kernel-*"] with OnlMountContextReadWrite("ONL-BOOT", self.logger) as d: for f in os.listdir(X86_64_UPGRADE_DIR): for pattern in X86_64_UPGRADE_KERNEL_PATTERNS: if fnmatch.fnmatch(f, pattern): self.copyfile(os.path.join(X86_64_UPGRADE_DIR, f), os.path.join(d.directory, f)) initrd = None for c in sysconfig.upgrade.loader.package.grub: initrd = os.path.join(X86_64_UPGRADE_DIR, c) if os.path.exists(initrd): break else: initrd = None if initrd: self.copyfile( initrd, os.path.join(d.directory, "%s.cpio.gz" % self.platform.platform())) else: self.abort("Initrd is missing. Upgrade cannot continue.") # Disabled until it can be resolved with the new installer. #src = "/lib/platform-config/current/onl/boot/grub.cfg" #dst = os.path.join(d.directory, "grub/grub.cfg") #if os.path.exists(src): # self.copyfile(src, dst) # installer assumes that partitions are unmounted self.log = self.logger # ha ha, SubprocessMixin api is different pm = InstallUtils.ProcMountsParser() for m in pm.mounts: if m.dir.startswith('/mnt/onl'): self.logger.warn("unmounting %s (--force)", m.dir) self.check_call(( 'umount', m.dir, )) onlPlatform = onl.platform.current.OnlPlatform() with OnieBootContext(log=self.logger) as octx: path = os.path.join(octx.initrdDir, "etc/machine.conf") machineConf = ConfUtils.MachineConf(path=path) # hold on to the ONIE boot context for grub access installerConf = ConfUtils.InstallerConf(path="/dev/null") # XXX fill in installerConf fields installerConf.installer_platform = onlPlatform.platform() installerConf.installer_arch = machineConf.onie_arch installerConf.installer_platform_dir = os.path.join( "/lib/platform-config", onlPlatform.platform()) mfPath = os.path.join(sysconfig.upgrade.loader.package.dir, "manifest.json") mf = onl.versions.OnlVersionManifest(mfPath) installerConf.onl_version = mf.RELEASE_ID grubEnv = ConfUtils.ChrootGrubEnv(octx.initrdDir, bootDir=octx.onieDir, path="/grub/grubenv", log=self.logger.getChild("grub")) ubootEnv = None installer = self.installer_klass( machineConf=machineConf, installerConf=installerConf, platformConf=onlPlatform.platform_config, grubEnv=grubEnv, ubootEnv=ubootEnv, force=True, log=self.logger) installer.upgradeBootLoader() installer.shutdown() self.reboot()