예제 #1
0
    def fetch(self, fetcher, progress):
        # FIXME (20050517): figure out a way to show progress

        # FIXME (20050517): we need a digest and RPC call to compare
        # against latest digest

        # Figure out how to constrain the rhn channel retrieval, if at all.
        channelList = None
        if rhnoptions.hasOption("channel"):
            channelList = rhnoptions.getOption("channel")

        pkgs = rhnPackages.listAllAvailablePackagesComplete(channelList)
        progress.show()

        # If this is an installall operation, we will purposely exclude patch
        # clusters because all available patches will be installed anyway.
        if rhnoptions.hasOption("action") and \
           rhnoptions.getOption("action") == "installall":
            toRemove = []
            for pkg in pkgs:
                name = pkg[0]
                if name.startswith("patch-cluster-solaris-"):
                    toRemove.append(pkg)
            for pkg in toRemove:
                pkgs.remove(pkg)

        #print "  fetch(), pkgs: ", len(pkgs)

        self._pkgs = pkgs

        self.removeLoaders()
        loader = SolarisRHNLoader(self._pkgs)
        loader.setChannel(self)
        self._loaders.append(loader)


        return True
예제 #2
0
def solinstall(adminfile, path, pkg, prog=None):
    # NOTE: all error handling and reporting is done via Exceptions

    if pkg.name.startswith("patch-"):
        # Patch and patch cluster install
        tdir = tempfile.mkdtemp('-dir', 'solinstall-', '/var/tmp')
        pkgdir = ""
        ret = 0

        # Save the CWD for later, since we may chdir below.
        saved_cwd = os.getcwd()

        try:
            if os.path.isdir(path):
                pkgdir = path

            else:
                if not zipfile.is_zipfile(path):
                    raise UnzipException("patch %s not in a zip file: %s" % \
                                             (pkg.name, path))

                cmdstr = "unzip -u %s -d %s" % (path, tdir)
                ret, x = commands.getstatusoutput(cmdstr)

                if ret != 0:
                    raise UnzipException("patch %s: unzip of %s into %s failed: %s" % \
                                             (pkg.name, path, tdir, x))

                pd= os.listdir(tdir)
                pkgdir = os.path.join(tdir, pd[0])

                if len(pd) > 1:
                    raise UnzipException( \
                        "patch %s contained more than 1 directory: %s" % \
                            (pkg.name, pkgdir))

                if pkgdir == tdir:
                    raise UnzipException( \
                        "patch %s: zip file does not contain patch: %s" % \
                            (pkg.name, pkgdir))

            # change the permissions on the patch directory
            cmdstr = "chmod -R 777 %s" % tdir
            ret, x = commands.getstatusoutput(cmdstr)

            # default values
            status = 1
            output = ""
            cmd = ""

            if pkg.name.startswith("patch-cluster-solaris-"):
                if os.path.exists(os.path.join(pkgdir, 'install_cluster')):
                    cmd =  "%s/install_cluster -q" % pkgdir
                elif os.path.exists(os.path.join(pkgdir, 'installpatchset')):
                    cmd =  "%s/installpatchset --s10patchset" % pkgdir
                elif os.path.exists(os.path.join(pkgdir, 'installcluster')):
                    cmd =  "%s/installcluster --s10cluster" % pkgdir
                else:
                    raise PatchaddException("Neither install_cluster nor installcluster script found.")
                os.chdir(pkgdir)
            else:
                cmd = "patchadd -u %s" % pkgdir

#            print cmd
            status, output = commands.getstatusoutput(cmd)

            if status != 0:
                raise PatchaddException("status: %d, output: %s" % (status, output))

        finally:
            # Return to the saved working directory so we don't attempt to
            # remove the directory we're in.
            os.chdir(saved_cwd)

            # Cleanup temp dir
            if ret == 0:
                shutil.rmtree(tdir)

    else:
        # Package install
        #template = "pkgadd -a %s -n -d %s %s"
        template = "pkgadd -a %s"

        os_version = os.uname()[2]
        if os_version == "5.10":
            if rhnoptions.hasOption("global_zone") and \
               rhnoptions.getOption("global_zone"):
                # '-G' option to only install into the global zone on solaris 10
                #template = "pkgadd -G -a %s -n -d %s %s"
                template += " -G "

        if rhnoptions.hasOption("response") and \
            rhnoptions.getOption("response"):
        responsefile = rhnoptions.getOption("response")
                template += " -r %s" % (responsefile)

        template += " -n -d %s %s"
        cmd = template % (adminfile, path, pkg.name)
        print cmd
        status, output = commands.getstatusoutput(cmd)

    return status, output
예제 #3
0
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        if rhnoptions.hasOption("admin") and \
            rhnoptions.getOption("admin"):
        adminfile = rhnoptions.getOption("admin")
    else:
            adminfile = sysconf.get("solaris-adminfile", "/var/sadm/install/admin/default")

        # Compute upgrade packages
        upgrade = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [upgpkg for prv in pkg.provides
                                  for upg in prv.upgradedby
                                  for upgpkg in upg.packages
                                  if upgpkg.installed]
                upgpkgs.extend([prvpkg for upg in pkg.upgrades
                                       for prv in upg.providedby
                                       for prvpkg in prv.packages
                                       if prvpkg.installed])
                if upgpkgs:
                    upgrade[pkg] = True
                    for upgpkg in upgpkgs:
                        if upgpkg in changeset:
                            del changeset[upgpkg]
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = ["%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                        for pkg, op in path]
                lines.append("    "+" -> ".join(path))
            iface.error("\n".join(lines))
            sys.exit(-1)
        del sorter

        for pkg, op in sorted:
            if op is INSTALL and pkg in upgrade:
                # Upgrading something
                prog.setSubTopic(pkg, _("Upgrading %s") % pkg.name)
                prog.setSub(pkg, 0, 1, 1)
                prog.show()
                path = pkgpaths[pkg][0]
                status, output = solupgrade(adminfile, path, pkg, prog)
                prog.setSubDone(pkg)
                prog.show()
                if status != 0:
                    iface.warning(_("Got status %d upgrading %s:") % (status, pkg))
                    iface.warning(output)
                else:
                    iface.debug(_("Upgrading %s:") % pkg)
                    iface.debug(output)
            elif op is INSTALL:
                # Normal install
                prog.setSubTopic(pkg, _("Installing %s") % pkg.name)
                prog.setSub(pkg, 0, 1, 1)
                prog.show()
                path = pkgpaths[pkg][0]

                status = 0
                output = ""
                try:
                    status, output = solinstall(adminfile, path, pkg, prog)
                except PatchaddException, pae:
                    # Solaris patch cluster installs are tolerant of failed
                    # patches, and we should be too.  Just warn the user and
                    # keep going.
                    iface.warning( \
                        _("\nWARNING:  Installation of patch %s failed.\n%s") \
                            % (pkg.name, str(pae)))

                prog.setSubDone(pkg)
                prog.show()
                if status != 0:
                    iface.warning(_("Got status %d installing %s:") % (status, pkg))
                    iface.warning(output)
                else:
                    iface.debug(_("Installing %s:") % pkg)
                    iface.debug(output)
            else:
                # Remove
                prog.setSubTopic(pkg, _("Removing %s") % pkg.name)
                prog.setSub(pkg, 0, 1, 1)
                prog.show()
                status, output = solremove(adminfile, pkg, prog)
                prog.setSubDone(pkg)
                prog.show()
                if status != 0:
                    iface.warning(_("Got status %d removing %s:") % (status, pkg))
                    iface.warning(output)
                else:
                    iface.debug(_("Removing %s:") % pkg)
                    iface.debug(output)
예제 #4
0
파일: pm.py 프로젝트: T-D-Oe/spacewalk
def solinstall(adminfile, path, pkg, prog=None):
    # NOTE: all error handling and reporting is done via Exceptions

    if pkg.name.startswith("patch-"):
        # Patch and patch cluster install
        tdir = tempfile.mkdtemp('-dir', 'solinstall-', '/var/tmp')
        pkgdir = ""
        ret = 0

        # Save the CWD for later, since we may chdir below.
        saved_cwd = os.getcwd()

        try:
            if os.path.isdir(path):
                pkgdir = path

            else:
                if not zipfile.is_zipfile(path):
                    raise UnzipException("patch %s not in a zip file: %s" % \
                                             (pkg.name, path))

                cmdstr = "unzip -u %s -d %s" % (path, tdir)
                ret, x = commands.getstatusoutput(cmdstr)

                if ret != 0:
                    raise UnzipException("patch %s: unzip of %s into %s failed: %s" % \
                                             (pkg.name, path, tdir, x))

                pd= os.listdir(tdir)
                pkgdir = os.path.join(tdir, pd[0])

                if len(pd) > 1:
                    raise UnzipException( \
                        "patch %s contained more than 1 directory: %s" % \
                            (pkg.name, pkgdir))

                if pkgdir == tdir:
                    raise UnzipException( \
                        "patch %s: zip file does not contain patch: %s" % \
                            (pkg.name, pkgdir))

            # change the permissions on the patch directory
            cmdstr = "chmod -R 777 %s" % tdir
            ret, x = commands.getstatusoutput(cmdstr)

            # default values
            status = 1
            output = ""
            cmd = ""

            if pkg.name.startswith("patch-cluster-solaris-"):
                if os.path.exists(os.path.join(pkgdir, 'install_cluster')):
                    cmd =  "%s/install_cluster -q" % pkgdir
                elif os.path.exists(os.path.join(pkgdir, 'installpatchset')):
                    cmd =  "%s/installpatchset --s10patchset" % pkgdir
                elif os.path.exists(os.path.join(pkgdir, 'installcluster')):
                    cmd =  "%s/installcluster --s10cluster" % pkgdir
                else:
                    raise PatchaddException("Neither install_cluster nor installcluster script found.")
                os.chdir(pkgdir)
            else:
                cmd = "patchadd -u %s" % pkgdir

#            print cmd
            status, output = commands.getstatusoutput(cmd)

            if status != 0:
                raise PatchaddException("status: %d, output: %s" % (status, output))

        finally:
            # Return to the saved working directory so we don't attempt to
            # remove the directory we're in.
            os.chdir(saved_cwd)

            # Cleanup temp dir
            if ret == 0:
                shutil.rmtree(tdir)

    else:
        # Package install
        #template = "pkgadd -a %s -n -d %s %s"
        template = "pkgadd -a %s"

        os_version = os.uname()[2]
        if os_version == "5.10":
            if rhnoptions.hasOption("global_zone") and \
               rhnoptions.getOption("global_zone"):
                # '-G' option to only install into the global zone on solaris 10
                #template = "pkgadd -G -a %s -n -d %s %s"
                template += " -G "

        if rhnoptions.hasOption("response") and \
            rhnoptions.getOption("response"):
		responsefile = rhnoptions.getOption("response")
                template += " -r %s" % (responsefile)

        template += " -n -d %s %s"
        cmd = template % (adminfile, path, pkg.name)
        print cmd
        status, output = commands.getstatusoutput(cmd)

    return status, output
예제 #5
0
파일: pm.py 프로젝트: T-D-Oe/spacewalk
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        if rhnoptions.hasOption("admin") and \
            rhnoptions.getOption("admin"):
		adminfile = rhnoptions.getOption("admin")
	else:
            adminfile = sysconf.get("solaris-adminfile", "/var/sadm/install/admin/default")

        # Compute upgrade packages
        upgrade = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [upgpkg for prv in pkg.provides
                                  for upg in prv.upgradedby
                                  for upgpkg in upg.packages
                                  if upgpkg.installed]
                upgpkgs.extend([prvpkg for upg in pkg.upgrades
                                       for prv in upg.providedby
                                       for prvpkg in prv.packages
                                       if prvpkg.installed])
                if upgpkgs:
                    upgrade[pkg] = True
                    for upgpkg in upgpkgs:
                        if upgpkg in changeset:
                            del changeset[upgpkg]
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = ["%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                        for pkg, op in path]
                lines.append("    "+" -> ".join(path))
            iface.error("\n".join(lines))
            sys.exit(-1)
        del sorter

        for pkg, op in sorted:
            if op is INSTALL and pkg in upgrade:
                # Upgrading something
                prog.setSubTopic(pkg, _("Upgrading %s") % pkg.name)
                prog.setSub(pkg, 0, 1, 1)
                prog.show()
                path = pkgpaths[pkg][0]
                status, output = solupgrade(adminfile, path, pkg, prog)
                prog.setSubDone(pkg)
                prog.show()
                if status != 0:
                    iface.warning(_("Got status %d upgrading %s:") % (status, pkg))
                    iface.warning(output)
                else:
                    iface.debug(_("Upgrading %s:") % pkg)
                    iface.debug(output)
            elif op is INSTALL:
                # Normal install
                prog.setSubTopic(pkg, _("Installing %s") % pkg.name)
                prog.setSub(pkg, 0, 1, 1)
                prog.show()
                path = pkgpaths[pkg][0]

                status = 0
                output = ""
                try:
                    status, output = solinstall(adminfile, path, pkg, prog)
                except PatchaddException, pae:
                    # Solaris patch cluster installs are tolerant of failed
                    # patches, and we should be too.  Just warn the user and
                    # keep going.
                    iface.warning( \
                        _("\nWARNING:  Installation of patch %s failed.\n%s") \
                            % (pkg.name, str(pae)))

                prog.setSubDone(pkg)
                prog.show()
                if status != 0:
                    iface.warning(_("Got status %d installing %s:") % (status, pkg))
                    iface.warning(output)
                else:
                    iface.debug(_("Installing %s:") % pkg)
                    iface.debug(output)
            else:
                # Remove
                prog.setSubTopic(pkg, _("Removing %s") % pkg.name)
                prog.setSub(pkg, 0, 1, 1)
                prog.show()
                status, output = solremove(adminfile, pkg, prog)
                prog.setSubDone(pkg)
                prog.show()
                if status != 0:
                    iface.warning(_("Got status %d removing %s:") % (status, pkg))
                    iface.warning(output)
                else:
                    iface.debug(_("Removing %s:") % pkg)
                    iface.debug(output)