Example #1
0
    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()
Example #2
0
    def install_onie_updater(self, src_dir, updater):
        with OnlMountContextReadWrite(self.ONIE_UPDATER_CONTEXT, logger=None):
            if type(updater) is not list:
                updater = [updater]

            # Copy all files in the list to ONIE_UPDATER_PATH
            for f in updater:
                src = os.path.join(src_dir, f)
                dst = os.path.join(self.ONIE_UPDATER_PATH, f)
                self.copyfile(src, dst)
Example #3
0
 def write(self, dst=None, force_overwrite=True):
     self.validate()
     if dst:
         self._writef(dst)
         return True
     else:
         from onl.mounts import OnlMountContextReadWrite
         with OnlMountContextReadWrite("ONL-BOOT", logger=None):
             if not os.path.exists(self.BOOT_CONFIG_DEFAULT) or force_overwrite:
                 self._writef(self.BOOT_CONFIG_DEFAULT)
                 return True
         return False
Example #4
0
 def clean_onie_updater(self):
     with OnlMountContextReadWrite(self.ONIE_UPDATER_CONTEXT, logger=None):
         updater = os.path.join(self.ONIE_UPDATER_PATH, "onie-updater")
         if os.path.exists(updater):
             self.logger.info("Removing previous onie-updater.")
             os.remove(updater)
Example #5
0
 def __init__(self, logger):
     OnlMountContextReadWrite.__init__(self, "ONL-CONFIG", logger)
Example #6
0
 def __init__(self, logger):
     OnlMountContextReadWrite.__init__(self, "ONL-CONFIG", logger)
Example #7
0
    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()
Example #8
0
def boot_entry_set(index):
    with OnlMountContextReadWrite("ONL-BOOT", logger=None) as ob:
        subprocess.check_call("/usr/sbin/grub-set-default --boot-directory=%s %d" % (ob.directory, index), shell=True)