Ejemplo n.º 1
0
 def _install(self, pkgpath, progress_cb):
     try:
         tar_size = os.path.getsize(pkgpath)
     except:
         errstr = _('Failed on get tar pakcage size "%s"') % (pkgpath, )
         logger.e(errstr)
         return errstr
     
     try:
         tarobj = tarfile.open(fileobj=CBFileObj(pkgpath, (progress_cb, tar_size)))
     except:
         errstr = _('Failed on create tarfile object on file "%s" size"%d"\n') % (pkgpath, tar_size)
         logger.e(errstr)
         return errstr
     
     try:
         tarobj.extractall(path=self.tgtsys_root)
     except:
         if tarobj:
             tarobj.close()
         errstr = _('Failed on extract file "%s" size"%d" to directory "%s"\n') % (pkgpath, tar_size, self.tgtsys_root)
         logger.e(errstr)
         return errstr
     
     try:
         tarobj.close()
     except:
         logger.w('Close tar pakcage failed path %s size %s' % (pkgpath, tar_size))
         
     return 0
Ejemplo n.º 2
0
    def preInstall(self, packages=None, groups=None):
        """ Perform pre-installation tasks. """
        self.progress.send_message(_("Starting package installation process"))

        self._writeInstallConfig()
        self.checkSoftwareSelection()

        # doPreInstall
        # create mountpoints for protected device mountpoints (?)
        # write static configs (storage, modprobe.d/anaconda.conf, network, keyboard)
        #   on upgrade, just make sure /etc/mtab is a symlink to /proc/self/mounts

        if not self.flags.upgrade: #not self.data.upgrade.upgrade:
            # this adds nofsync, which speeds things up but carries a risk of
            # rpmdb data loss if a crash occurs. that's why we only do it on
            # initial install and not for upgrades.
            rpm.addMacro("__dbi_htconfig", #@UndefinedVariable
                         "hash nofsync %{__dbi_other} %{__dbi_perms}")

        if self.flags.excludeDocs: #if self.data.packages.excludeDocs:
            rpm.addMacro("_excludedocs", "1") #@UndefinedVariable

        if self.flags.selinux:
            for d in ["/tmp/updates",
                      "/etc/selinux/targeted/contexts/files",
                      "/etc/security/selinux/src/policy",
                      "/etc/security/selinux"]:
                f = d + "/file_contexts"
                if os.access(f, os.R_OK):
                    rpm.addMacro("__file_context_path", f) #@UndefinedVariable
                    break
        else:
            rpm.addMacro("__file_context_path", "%{nil}") #@UndefinedVariable
Ejemplo n.º 3
0
    def preInstall(self, packages=None, groups=None):
        """ Perform pre-installation tasks. """
        self.progress.send_message(_("Starting package installation process"))

        self._writeInstallConfig()
        self.checkSoftwareSelection()

        # doPreInstall
        # create mountpoints for protected device mountpoints (?)
        # write static configs (storage, modprobe.d/anaconda.conf, network, keyboard)
        #   on upgrade, just make sure /etc/mtab is a symlink to /proc/self/mounts

        if not self.flags.upgrade:  #not self.data.upgrade.upgrade:
            # this adds nofsync, which speeds things up but carries a risk of
            # rpmdb data loss if a crash occurs. that's why we only do it on
            # initial install and not for upgrades.
            rpm.addMacro(
                "__dbi_htconfig",  #@UndefinedVariable
                "hash nofsync %{__dbi_other} %{__dbi_perms}")

        if self.flags.excludeDocs:  #if self.data.packages.excludeDocs:
            rpm.addMacro("_excludedocs", "1")  #@UndefinedVariable

        if self.flags.selinux:
            for d in [
                    "/tmp/updates", "/etc/selinux/targeted/contexts/files",
                    "/etc/security/selinux/src/policy", "/etc/security/selinux"
            ]:
                f = d + "/file_contexts"
                if os.access(f, os.R_OK):
                    rpm.addMacro("__file_context_path", f)  #@UndefinedVariable
                    break
        else:
            rpm.addMacro("__file_context_path", "%{nil}")  #@UndefinedVariable
Ejemplo n.º 4
0
def test_x_settings(mia, operid, x_settings):
    if not os.path.exists(CF.D.TGTSYS_ROOT):
        return  _('Failed: The target system is not exists yet.')
    if not os.path.exists(os.path.join(CF.D.TGTSYS_ROOT, 'usr/bin/xinit')):
        return  _('Failed: xinit is not installed.')
    if not os.path.exists(os.path.join(CF.D.TGTSYS_ROOT, 'usr/bin/X')):
        return  _('Failed: X is not inistalled.')

    mark_file = os.path.join(CF.D.TGTSYS_ROOT, 'tmp/testxdlg/probe_x_mark')
    gen_x_config(mia, operid, x_settings)
    os.system('/bin/gunzip -c %s | /bin/tar x -C %s' % \
              (os.path.join('operations', 'testxdlg.tar.gz'), CF.D.TGTSYS_ROOT))
    os.system('/bin/touch %s' % mark_file)
    os.system('/usr/sbin/chroot %s /usr/bin/xinit /tmp/testxdlg/testxdlg -- /usr/bin/X :1' % CF.D.TGTSYS_ROOT)
    if not os.path.exists(mark_file):
        result = 'SUCCESS'
    else:
        result = _('Failed: Please recheck X settings.')
    os.system('/bin/rm -rf %s' % os.path.join(CF.D.TGTSYS_ROOT, 'tmp/testxdlg'))
    return  result
Ejemplo n.º 5
0
    def callback(self, event, amount, total, key, userdata):
        """ Yum install callback. """
        if event == rpm.RPMCALLBACK_TRANS_START: #@UndefinedVariable
            if amount == 6:
                self.progress.send_message(_("Preparing transaction from installation source"))
            self.total_actions = total
            self.completed_actions = 0
        elif event == rpm.RPMCALLBACK_TRANS_PROGRESS: #@UndefinedVariable
            # amount / total complete
            pass
        elif event == rpm.RPMCALLBACK_TRANS_STOP: #@UndefinedVariable
            # we are done
            pass
        elif event == rpm.RPMCALLBACK_INST_OPEN_FILE: #@UndefinedVariable
            # update status that we're installing/upgrading %h
            # return an open fd to the file
            txmbr = self._get_txmbr(key)[1]

            # If self.completed_actions is still None, that means this package
            # is being opened to retrieve a %pretrans script. Don't log that
            # we're installing the package unless we've been called with a
            # TRANS_START event.
            if self.completed_actions is not None:
                if self.upgrade:
                    mode = _("Upgrading")
                else:
                    mode = _("Installing")

                self.completed_actions += 1
                msg_format = "%s %s (%d/%d)"
                progress_package = txmbr.name
                if txmbr.arch not in ["noarch", self.base_arch]:
                    progress_package = "%s.%s" % (txmbr.name, txmbr.arch)

                progress_msg =  msg_format % (mode, progress_package,
                                              self.completed_actions,
                                              self.total_actions)
                log_msg = msg_format % (mode, txmbr.po,
                                        self.completed_actions,
                                        self.total_actions)
                logger.info(log_msg)
                self.install_log.write(log_msg+"\n")
                self.install_log.flush()

                self.progress.send_message(progress_msg)

            self.package_file = None
            repo = self._yum.repos.getRepo(txmbr.po.repoid)
            while self.package_file is None:
                try:
                    # checkfunc gets passed to yum's use of URLGrabber which
                    # then calls it with the file being fetched. verifyPkg
                    # makes sure the checksum matches the one in the metadata.
                    #
                    # From the URLGrab documents:
                    # checkfunc=(function, ('arg1', 2), {'kwarg': 3})
                    # results in a callback like:
                    #   function(obj, 'arg1', 2, kwarg=3)
                    #     obj.filename = '/tmp/stuff'
                    #     obj.url = 'http://foo.com/stuff'
                    checkfunc = (self._yum.verifyPkg, (txmbr.po, 1), {})
                    package_path = repo.getPackage(txmbr.po, checkfunc=checkfunc)
                except yum.URLGrabError as e:
                    logger.error("URLGrabError: %s" % (e,))
                    exn = PayloadInstallError("failed to get package")
                    #if errorHandler.cb(exn, txmbr.po) == ERROR_RAISE:
                    raise exn
                except (yum.Errors.NoMoreMirrorsRepoError, IOError):
                    if os.path.exists(txmbr.po.localPkg()):
                        os.unlink(txmbr.po.localPkg())
                        logger.debug("retrying download of %s" % txmbr.po)
                        continue
                    exn = PayloadInstallError("failed to open package")
                    #if errorHandler.cb(exn, txmbr.po) == ERROR_RAISE:
                    raise exn
                except yum.Errors.RepoError:
                    continue

                self.package_file = open(package_path)

            return self.package_file.fileno()
        elif event == rpm.RPMCALLBACK_INST_PROGRESS: #@UndefinedVariable
            txmbr = self._get_txmbr(key)[1]
            progress_package = txmbr.name
            if txmbr.arch not in ["noarch", self.base_arch]:
                progress_package = "%s.%s" % (txmbr.name, txmbr.arch)
            #self.progress.send_message('%s (%s/%s)' % (progress_package, amount, total))
        elif event == rpm.RPMCALLBACK_INST_CLOSE_FILE: #@UndefinedVariable
            # close and remove the last opened file
            # update count of installed/upgraded packages
            package_path = self.package_file.name
            self.package_file.close()
            self.package_file = None

            if package_path.startswith(_yum_cache_dir):
                try:
                    os.unlink(package_path)
                except OSError as e:
                    logger.debug("unable to remove file %s" % e.strerror)

            # rpm doesn't tell us when it's started post-trans stuff which can
            # take a very long time.  So when it closes the last package, just
            # display the message.
            if self.completed_actions == self.total_actions:
                self.progress.send_message(_("Performing post-install setup tasks"))
        elif event == rpm.RPMCALLBACK_UNINST_START: #@UndefinedVariable
            # update status that we're cleaning up %key
            #self.progress.set_text(_("Cleaning up %s" % key))
            pass
        elif event in (rpm.RPMCALLBACK_CPIO_ERROR, #@UndefinedVariable
                       rpm.RPMCALLBACK_UNPACK_ERROR, #@UndefinedVariable
                       rpm.RPMCALLBACK_SCRIPT_ERROR): #@UndefinedVariable
            name = self._get_txmbr(key)[0]

            # Script errors store whether or not they're fatal in "total".  So,
            # we should only error out for fatal script errors or the cpio and
            # unpack problems.
            if event != rpm.RPMCALLBACK_SCRIPT_ERROR or total: #@UndefinedVariable
                exn = PayloadInstallError("cpio, unpack, or fatal script error")
                #if errorHandler.cb(exn, name) == ERROR_RAISE:
                raise exn
Ejemplo n.º 6
0
    def callback(self, event, amount, total, key, userdata):
        """ Yum install callback. """
        if event == rpm.RPMCALLBACK_TRANS_START:  #@UndefinedVariable
            if amount == 6:
                self.progress.send_message(
                    _("Preparing transaction from installation source"))
            self.total_actions = total
            self.completed_actions = 0
        elif event == rpm.RPMCALLBACK_TRANS_PROGRESS:  #@UndefinedVariable
            # amount / total complete
            pass
        elif event == rpm.RPMCALLBACK_TRANS_STOP:  #@UndefinedVariable
            # we are done
            pass
        elif event == rpm.RPMCALLBACK_INST_OPEN_FILE:  #@UndefinedVariable
            # update status that we're installing/upgrading %h
            # return an open fd to the file
            txmbr = self._get_txmbr(key)[1]

            # If self.completed_actions is still None, that means this package
            # is being opened to retrieve a %pretrans script. Don't log that
            # we're installing the package unless we've been called with a
            # TRANS_START event.
            if self.completed_actions is not None:
                if self.upgrade:
                    mode = _("Upgrading")
                else:
                    mode = _("Installing")

                self.completed_actions += 1
                msg_format = "%s %s (%d/%d)"
                progress_package = txmbr.name
                if txmbr.arch not in ["noarch", self.base_arch]:
                    progress_package = "%s.%s" % (txmbr.name, txmbr.arch)

                progress_msg = msg_format % (mode, progress_package,
                                             self.completed_actions,
                                             self.total_actions)
                log_msg = msg_format % (mode, txmbr.po, self.completed_actions,
                                        self.total_actions)
                logger.info(log_msg)
                self.install_log.write(log_msg + "\n")
                self.install_log.flush()

                self.progress.send_message(progress_msg)

            self.package_file = None
            repo = self._yum.repos.getRepo(txmbr.po.repoid)
            while self.package_file is None:
                try:
                    # checkfunc gets passed to yum's use of URLGrabber which
                    # then calls it with the file being fetched. verifyPkg
                    # makes sure the checksum matches the one in the metadata.
                    #
                    # From the URLGrab documents:
                    # checkfunc=(function, ('arg1', 2), {'kwarg': 3})
                    # results in a callback like:
                    #   function(obj, 'arg1', 2, kwarg=3)
                    #     obj.filename = '/tmp/stuff'
                    #     obj.url = 'http://foo.com/stuff'
                    checkfunc = (self._yum.verifyPkg, (txmbr.po, 1), {})
                    package_path = repo.getPackage(txmbr.po,
                                                   checkfunc=checkfunc)
                except yum.URLGrabError as e:
                    logger.error("URLGrabError: %s" % (e, ))
                    exn = PayloadInstallError("failed to get package")
                    #if errorHandler.cb(exn, txmbr.po) == ERROR_RAISE:
                    raise exn
                except (yum.Errors.NoMoreMirrorsRepoError, IOError):
                    if os.path.exists(txmbr.po.localPkg()):
                        os.unlink(txmbr.po.localPkg())
                        logger.debug("retrying download of %s" % txmbr.po)
                        continue
                    exn = PayloadInstallError("failed to open package")
                    #if errorHandler.cb(exn, txmbr.po) == ERROR_RAISE:
                    raise exn
                except yum.Errors.RepoError:
                    continue

                self.package_file = open(package_path)

            return self.package_file.fileno()
        elif event == rpm.RPMCALLBACK_INST_PROGRESS:  #@UndefinedVariable
            txmbr = self._get_txmbr(key)[1]
            progress_package = txmbr.name
            if txmbr.arch not in ["noarch", self.base_arch]:
                progress_package = "%s.%s" % (txmbr.name, txmbr.arch)
            #self.progress.send_message('%s (%s/%s)' % (progress_package, amount, total))
        elif event == rpm.RPMCALLBACK_INST_CLOSE_FILE:  #@UndefinedVariable
            # close and remove the last opened file
            # update count of installed/upgraded packages
            package_path = self.package_file.name
            self.package_file.close()
            self.package_file = None

            if package_path.startswith(_yum_cache_dir):
                try:
                    os.unlink(package_path)
                except OSError as e:
                    logger.debug("unable to remove file %s" % e.strerror)

            # rpm doesn't tell us when it's started post-trans stuff which can
            # take a very long time.  So when it closes the last package, just
            # display the message.
            if self.completed_actions == self.total_actions:
                self.progress.send_message(
                    _("Performing post-install setup tasks"))
        elif event == rpm.RPMCALLBACK_UNINST_START:  #@UndefinedVariable
            # update status that we're cleaning up %key
            #self.progress.set_text(_("Cleaning up %s" % key))
            pass
        elif event in (
                rpm.RPMCALLBACK_CPIO_ERROR,  #@UndefinedVariable
                rpm.RPMCALLBACK_UNPACK_ERROR,  #@UndefinedVariable
                rpm.RPMCALLBACK_SCRIPT_ERROR):  #@UndefinedVariable
            name = self._get_txmbr(key)[0]

            # Script errors store whether or not they're fatal in "total".  So,
            # we should only error out for fatal script errors or the cpio and
            # unpack problems.
            if event != rpm.RPMCALLBACK_SCRIPT_ERROR or total:  #@UndefinedVariable
                exn = PayloadInstallError(
                    "cpio, unpack, or fatal script error")
                #if errorHandler.cb(exn, name) == ERROR_RAISE:
                raise exn