Esempio n. 1
0
    def _get_tasks(self, cmdline, db):
        result = set()

        # no arguments - pull everything for non-EOL releases
        if not cmdline.opsys:
            for osplugin in systems.values():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    raise FafError("Operating system '{0}' is not defined in "
                                   "storage".format(osplugin.nice_name))

                for db_release in db_opsys.releases:
                    if db_release.status != "EOL":
                        result.add((osplugin, db_release))

        # a single opsys - respect opsysrelease
        elif len(cmdline.opsys) == 1:
            if cmdline.opsys[0] not in systems:
                raise FafError("Operating system '{0}' is not supported"
                               .format(cmdline.opsys[0]))

            osplugin = systems[cmdline.opsys[0]]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                raise FafError("Operating system '{0}' is not defined in "
                               "storage".format(osplugin.nice_name))

            if len(cmdline.opsys_release) < 1:
                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))
            else:
                for release in cmdline.opsys_release:
                    db_release = get_osrelease(db, osplugin.nice_name, release)
                    if db_release is None:
                        self.log_warn("Operating system '{0} {1}' is not "
                                      "supported".format(osplugin.nice_name,
                                                         release))
                        continue

                    result.add((osplugin, db_release))

        # multiple opsys - pull all of their releases
        else:
            for opsys_name in cmdline.opsys:
                if not opsys_name in systems:
                    self.log_warn("Operating system '{0}' is not supported"
                                  .format(opsys_name))
                    continue

                osplugin = systems[opsys_name]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not defined in "
                                  "storage".format(osplugin.nice_name))
                    continue

                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))

        return sorted(result, key=lambda p_r: (p_r[1].opsys.name, p_r[1].version))
Esempio n. 2
0
    def _get_tasks(self, cmdline, db):
        result = set()

        # no arguments - pull everything for non-EOL releases
        if not cmdline.opsys:
            for osplugin in systems.values():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    raise FafError("Operating system '{0}' is not defined in "
                                   "storage".format(osplugin.nice_name))

                for db_release in db_opsys.releases:
                    if db_release.status != "EOL":
                        result.add((osplugin, db_release))

        # a single opsys - respect opsysrelease
        elif len(cmdline.opsys) == 1:
            if cmdline.opsys[0] not in systems:
                raise FafError("Operating system '{0}' is not supported"
                               .format(cmdline.opsys[0]))

            osplugin = systems[cmdline.opsys[0]]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                raise FafError("Operating system '{0}' is not defined in "
                               "storage".format(osplugin.nice_name))

            if not cmdline.opsys_release:
                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))
            else:
                for release in cmdline.opsys_release:
                    db_release = get_osrelease(db, osplugin.nice_name, release)
                    if db_release is None:
                        self.log_warn("Operating system '{0} {1}' is not "
                                      "supported".format(osplugin.nice_name,
                                                         release))
                        continue

                    result.add((osplugin, db_release))

        # multiple opsys - pull all of their releases
        else:
            for opsys_name in cmdline.opsys:
                if not opsys_name in systems:
                    self.log_warn("Operating system '{0}' is not supported"
                                  .format(opsys_name))
                    continue

                osplugin = systems[opsys_name]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not defined in "
                                  "storage".format(osplugin.nice_name))
                    continue

                for db_release in db_opsys.releases:
                    result.add((osplugin, db_release))

        return sorted(result, key=lambda p_r: (p_r[1].opsys.name, p_r[1].version))
Esempio n. 3
0
    def run(self, cmdline, db):
        result = set()

        if len(cmdline.opsys) < 1:
            for osname, osplugin in systems.items():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not installed".format(osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))
        else:
            for osname in cmdline.opsys:
                if osname not in systems:
                    self.log_warn("Operating system '{0}' is not supported".format(osname))
                    continue

                osplugin = systems[osname]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not installed".format(osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))

        for osplugin, db_opsys in result:
            db_components = get_components_by_opsys(db, db_opsys)
            components = {}
            for db_component in db_components:
                components[db_component.name] = db_component

            i = 0
            db_builds = osplugin.get_build_candidates(db)
            for db_build in db_builds:
                i += 1

                self.log_info("[{0} / {1}] Processing '{2}'".format(i, len(db_builds), db_build.nevr()))

                comp_name = db_build.base_package_name
                if comp_name not in components:
                    self.log_debug(
                        "Component '{0}' not found in operating " "system '{1}'".format(comp_name, osplugin.nice_name)
                    )
                    continue

                db_component = components[comp_name]

                if any(db_component == bcomp.component for bcomp in db_build.components):
                    self.log_debug("Already assigned")
                    continue

                self.log_info("Assigning to component '{0}'".format(comp_name))
                db_buildcomponent = BuildComponent()
                db_buildcomponent.build = db_build
                db_buildcomponent.component = db_component
                db.session.add(db_buildcomponent)

            db.session.flush()
Esempio n. 4
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist"
                           .format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed"
                           .format(opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '{0} {1}' is not defined"
                          .format(opsys.nice_name, cmdline.opsys_release))
            return 1

        if cmdline.status is not None and cmdline.status != db_release.status:
            if not cmdline.status in OpSysReleaseStatus.enums:
                self.log_error("Status '{0}' is invalid".format(cmdline.status))
                return 1

            self.log_info("Updating status of '{0} {1}': {2} ~> {3}"
                          .format(opsys.nice_name, db_release.version,
                                  db_release.status, cmdline.status))

            db_release.status = cmdline.status

        db.session.flush()
Esempio n. 5
0
    def run(self, cmdline, db):
        repo = (db.session.query(Repo).filter(
            Repo.name == cmdline.NAME).first())

        if not repo:
            self.log_error("Repository '{0}' not found".format(cmdline.NAME))
            return 1

        arch_list = []
        opsys_list = []

        for item_name in cmdline.OPSYS + cmdline.ARCH:
            opsys = get_opsys_by_name(db, item_name)
            arch = get_arch_by_name(db, item_name)

            if not (opsys or arch):
                self.log_error("Item '{0}' not found".format(item_name))

                return 1

            if opsys:
                opsys_list.append(opsys)
            else:
                arch_list.append(arch)

        repo.opsys_list += opsys_list
        repo.arch_list += arch_list

        db.session.flush()

        self.log_info("Assigned '{0}' to {1} operating system(s)"
                      " and {2} architecture(s)".format(
                          repo.name, len(opsys_list), len(arch_list)))
Esempio n. 6
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist"
                           .format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed"
                           .format(opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '{0} {1}' is not defined"
                          .format(opsys.nice_name, cmdline.opsys_release))
            return 1

        if cmdline.status is not None and cmdline.status != db_release.status:
            if not cmdline.status in OpSysReleaseStatus.enums:
                self.log_error("Status '{0}' is invalid".format(cmdline.status))
                return 1

            self.log_info("Updating status of '{0} {1}': {2} ~> {3}"
                          .format(opsys.nice_name, db_release.version,
                                  db_release.status, cmdline.status))

            db_release.status = cmdline.status

        db.session.flush()
Esempio n. 7
0
    def run(self, cmdline, db):
        for opsys in cmdline.OPSYS:
            db_opsys = get_opsys_by_name(db, opsys)

            if not db_opsys:
                self.log_warn(
                    "Operating system '{0}' not found".format(db_opsys))
                continue

            if db_opsys.releases:
                self.log_warn(
                    "Unable to delete operating system with associated"
                    " releases. Following is the list of associated "
                    " releases:")
                for release in db_opsys.releases:
                    self.log_warn(release)

                continue

            self.log_info("Removing operating system '{0}'".format(opsys))

            db.session.delete(db_opsys)
            db.session.flush()

        return 0
Esempio n. 8
0
    def run(self, cmdline, db):
        repo = (db.session.query(Repo)
                          .filter(Repo.name == cmdline.NAME)
                          .first())

        if not repo:
            self.log_error("Repository '{0}' not found"
                           .format(cmdline.NAME))
            return 1

        arch_list = []
        opsys_list = []

        for item_name in cmdline.OPSYS + cmdline.ARCH:
            opsys = get_opsys_by_name(db, item_name)
            arch = get_arch_by_name(db, item_name)

            if not (opsys or arch):
                #If name is rhel we will search Red Hat Enterprise Linux
                if item_name == "rhel":
                    item_name = "Red Hat Enterprise Linux"
                    opsys = get_opsys_by_name(db, item_name)
                    
                    if not opsys:   
                        self.log_error("Item '{0}' not found"
                               .format(item_name))
                        return 1
                else:
                    self.log_error("Item '{0}' not found"
                               .format(item_name))
                    return 1

            if opsys:
                opsys_list.append(opsys)
            else:
                arch_list.append(arch)

        repo.opsys_list += opsys_list
        repo.arch_list += arch_list

        db.session.flush()

        self.log_info("Assigned '{0}' to {1} operating system(s)"
                      " and {2} architecture(s)"
                      .format(repo.name, len(opsys_list), len(arch_list)))
Esempio n. 9
0
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error("Selected operating system '{0}' is not supported."
                           .format(cmdline.OPSYS))
            return 1

        self.log_info("Selected operating system: '{0}'"
                      .format(cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported."
                           .format(cmdline.RELEASE))
            return 1

        self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # find all builds, that are assigned to this opsysrelease but none other
        # architecture is missed out intentionally
        bosra1 = aliased(BuildOpSysReleaseArch)
        bosra2 = aliased(BuildOpSysReleaseArch)
        all_builds = (db.session.query(bosra1)
                      .filter(bosra1.opsysrelease_id == opsysrelease.id)
                      .filter(~bosra1.build_id.in_(
                          db.session.query(bosra2.build_id)
                          .filter(bosra1.build_id == bosra2.build_id)
                          .filter(bosra2.opsysrelease_id != opsysrelease.id)
                      ))
                      .all())

        #delete all records, where the opsysrelease.id is present
        query = (db.session.query(BuildOpSysReleaseArch)
                 .filter(BuildOpSysReleaseArch.opsysrelease_id == opsysrelease.id))

        self.log_info("{0} links will be removed".format(query.count()))
        if cmdline.dry_run:
            self.log_info("Dry run active, removal will be skipped")
        else:
            query.delete()

        #delete all builds and packages from them
        for build in all_builds:
            for pkg in (db.session.query(Package)
                        .filter(Package.build_id == build.build_id)
                        .all()):
                self.delete_package(pkg, db, cmdline.dry_run)
Esempio n. 10
0
    def get_db_opsys(self, db, cmdline_opsys):
        """
        Get opsys object from database or raise
        FafError if not available
        """

        opsys_name = self.get_opsys_name(cmdline_opsys)
        db_opsys = get_opsys_by_name(db, opsys_name)
        if db_opsys is None:
            raise FafError(
                "Operating system '{0}' is not installed".format(opsys_name))

        return db_opsys
Esempio n. 11
0
    def get_db_opsys(self, db, cmdline_opsys):
        """
        Get opsys object from database or raise
        FafError if not available
        """

        opsys_name = self.get_opsys_name(cmdline_opsys)
        db_opsys = get_opsys_by_name(db, opsys_name)
        if db_opsys is None:
            raise FafError("Operating system '{0}' is not installed"
                           .format(opsys_name))

        return db_opsys
Esempio n. 12
0
    def run(self, cmdline, db):
        opsys = get_opsys_by_name(db, cmdline.NAME)

        if opsys:
            self.log_error("Operating system '{0}' already defined"
                           .format(cmdline.NAME))
            return 1

        self.log_info("Adding operating system '{0}'".format(cmdline.NAME))

        new = OpSys()
        new.name = cmdline.NAME
        db.session.add(new)
        db.session.flush()
Esempio n. 13
0
    def run(self, cmdline, db):
        opsys = get_opsys_by_name(db, cmdline.NAME)

        if opsys:
            self.log_error("Operating system '{0}' already defined".format(
                cmdline.NAME))
            return 1

        self.log_info("Adding operating system '{0}'".format(cmdline.NAME))

        new = OpSys()
        new.name = cmdline.NAME
        db.session.add(new)
        db.session.flush()
Esempio n. 14
0
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error(
                "Selected operating system '{0}' is not supported.".format(
                    cmdline.OPSYS))
            return 1

        self.log_info("Selected operating system: '{0}'".format(cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported.".format(
                cmdline.RELEASE))
            return 1

        self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # find all builds, that are assigned to this opsysrelease but none other
        # architecture is missed out intentionally
        bosra1 = aliased(BuildOpSysReleaseArch)
        bosra2 = aliased(BuildOpSysReleaseArch)
        all_builds = (db.session.query(bosra1).filter(
            bosra1.opsysrelease_id == opsysrelease.id).filter(
                ~bosra1.build_id.in_(
                    db.session.query(bosra2.build_id).filter(
                        bosra1.build_id == bosra2.build_id).filter(
                            bosra2.opsysrelease_id != opsysrelease.id))).all())

        #delete all records, where the opsysrelease.id is present
        query = (db.session.query(BuildOpSysReleaseArch).filter(
            BuildOpSysReleaseArch.opsysrelease_id == opsysrelease.id))

        self.log_info("{0} links will be removed".format(query.count()))
        if cmdline.dry_run:
            self.log_info("Dry run active, removal will be skipped")
        else:
            query.delete()

        #delete all builds and packages from them
        for build in all_builds:
            for pkg in (db.session.query(Package).filter(
                    Package.build_id == build.build_id).all()):
                self.delete_package(pkg, cmdline.dry_run)
        return 0
Esempio n. 15
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist".format(
                cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed".format(
                opsys.nice_name))
            return 1

        db_component = get_component_by_name(db, cmdline.COMPONENT,
                                             opsys.nice_name)
        if db_component is None:
            self.log_info(
                "Adding component '{0}' to operating system '{1}'".format(
                    cmdline.COMPONENT, opsys.nice_name))

            db_component = OpSysComponent()
            db_component.opsys = db_opsys
            db_component.name = cmdline.COMPONENT
            db.session.add(db_component)

        for release in cmdline.opsys_release:
            db_release = get_osrelease(db, opsys.nice_name, release)
            if db_release is None:
                self.log_warn("Release '{0} {1}' is not defined".format(
                    opsys.nice_name, release))
                continue

            db_relcomponent = get_component_by_name_release(
                db, db_release, cmdline.COMPONENT)
            if db_relcomponent is None:
                self.log_info("Adding component '{0}' to '{1} {2}'".format(
                    cmdline.COMPONENT, opsys.nice_name, release))

                db_relcomponent = OpSysReleaseComponent()
                db_relcomponent.component = db_component
                db_relcomponent.release = db_release
                db.session.add(db_relcomponent)

        db.session.flush()
        return 0
Esempio n. 16
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist"
                           .format(cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed"
                           .format(opsys.nice_name))
            return 1

        db_component = get_component_by_name(db, cmdline.COMPONENT,
                                             opsys.nice_name)
        if db_component is None:
            self.log_info("Adding component '{0}' to operating system '{1}'"
                          .format(cmdline.COMPONENT, opsys.nice_name))

            db_component = OpSysComponent()
            db_component.opsys = db_opsys
            db_component.name = cmdline.COMPONENT
            db.session.add(db_component)

        for release in cmdline.opsys_release:
            db_release = get_osrelease(db, opsys.nice_name, release)
            if db_release is None:
                self.log_warn("Release '{0} {1}' is not defined"
                              .format(opsys.nice_name, release))
                continue

            db_relcomponent = get_component_by_name_release(db, db_release,
                                                            cmdline.COMPONENT)
            if db_relcomponent is None:
                self.log_info("Adding component '{0}' to '{1} {2}'"
                              .format(cmdline.COMPONENT,
                                      opsys.nice_name, release))

                db_relcomponent = OpSysReleaseComponent()
                db_relcomponent.component = db_component
                db_relcomponent.release = db_release
                db.session.add(db_relcomponent)

        db.session.flush()
        return 0
Esempio n. 17
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify the operating system.")
            return 1

        if cmdline.opsys_release is None:
            self.log_error("You must specify the operating system release.")
            return 1

        if cmdline.opsys not in systems:
            self.log_error("Operating system '%s' does not exist",
                           cmdline.opsys)
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '%s' is not installed",
                           opsys.nice_name)
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '%s %s' is not defined", opsys.nice_name,
                          cmdline.opsys_release)
            return 1

        self.log_info("Deleting release '{0} {1}'".format(
            opsys.nice_name, cmdline.opsys_release))

        db_release_id = db_release.id

        self._delete_mantis_bugs(db, db_release_id)
        self._delete_bugzilla_bugs(db, db_release_id)
        self._delete_release_builds(db, db_release_id)
        self._delete_release_repos(db, db_release_id)
        self._delete_release_reports(db, db_release_id)
        self._delete_release_problems(db, db_release_id)

        (db.session.query(st.OpSysReleaseComponent).filter(
            st.OpSysReleaseComponent.opsysreleases_id == db_release_id).delete(
                False))

        db.session.delete(db_release)
        db.session.flush()

        self.log_info("Done")
        return 0
Esempio n. 18
0
    def find_solution_ureport(self,
                              db,
                              ureport,
                              osr=None) -> Optional[SfPrefilterSolution]:
        """
        Check whether uReport matches a knowledgebase
        entry. Return a pyfaf.storage.SfPrefilterSolution object or None.
        """

        if "ureport_version" in ureport and ureport["ureport_version"] == 1:
            ureport = ureport1to2(ureport)
            validate(ureport)

        db_opsys = None
        if osr is not None:
            db_opsys = osr.opsys

        osname = ureport["os"]["name"]
        if osname not in systems:
            log.warning("Operating system '%s' is not supported", osname)
        else:
            osplugin = systems[osname]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                log.warning(
                    "Operaring system '%s' is not installed in storage",
                    osplugin.nice_name)
            else:
                pkgname_parsers = self._get_pkgname_parsers(db,
                                                            db_opsys=db_opsys)
                for parser, solution in pkgname_parsers.items():
                    if osplugin.check_pkgname_match(ureport["packages"],
                                                    parser):
                        return self._sfps_to_solution(solution)

        ptype = ureport["problem"]["type"]
        if ptype not in problemtypes:
            log.warning("Problem type '%s' is not supported", ptype)
        else:
            problemplugin = problemtypes[ptype]
            btpath_parsers = self._get_btpath_parsers(db, db_opsys=db_opsys)
            for parser, solution in btpath_parsers.items():
                if problemplugin.check_btpath_match(ureport["problem"],
                                                    parser):
                    return self._sfps_to_solution(solution)

        return None
Esempio n. 19
0
    def run(self, cmdline, db):
        if cmdline.opsys is None:
            self.log_error("You must specify the operating system.")
            return 1

        if cmdline.opsys_release is None:
            self.log_error("You must specify the operating system release.")
            return 1

        if cmdline.opsys not in systems:
            self.log_error("Operating system '%s' does not exist", cmdline.opsys)
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '%s' is not installed", opsys.nice_name)
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is None:
            self.log_info("Release '%s %s' is not defined", opsys.nice_name, cmdline.opsys_release)
            return 1

        self.log_info("Deleting release '{0} {1}'"
                      .format(opsys.nice_name, cmdline.opsys_release))

        db_release_id = db_release.id

        self._delete_mantis_bugs(db, db_release_id)
        self._delete_bugzilla_bugs(db, db_release_id)
        self._delete_release_builds(db, db_release_id)
        self._delete_release_repos(db, db_release_id)
        self._delete_release_reports(db, db_release_id)
        self._delete_release_problems(db, db_release_id)

        (db.session.query(st.OpSysReleaseComponent)
         .filter(st.OpSysReleaseComponent.opsysreleases_id == db_release_id)
         .delete(False))

        db.session.delete(db_release)
        db.session.flush()

        self.log_info("Done")
        return 0
Esempio n. 20
0
    def run(self, cmdline, db):
        opsys = get_opsys_by_name(db, cmdline.NAME)

        if not opsys:
            self.log_error("Operating system '{0}' not found"
                           .format(cmdline.NAME))
            return 1

        if opsys.releases:
            self.log_error("Unable to delete operating system with associated"
                           " releases. Following is the list of associated "
                           " releases:")
            for release in opsys.releases:
                self.log_error(release)

            return 1

        self.log_info("Removing operating system '{0}'".format(cmdline.NAME))

        db.session.delete(opsys)
        db.session.flush()
Esempio n. 21
0
    def find_solution_ureport(self, db, ureport, osr=None):
        """
        Check whether uReport matches a knowledgebase
        entry. Return a pyfaf.storage.SfPrefilterSolution object or None.
        """

        if "ureport_version" in ureport and ureport["ureport_version"] == 1:
            ureport = ureport1to2(ureport)
            validate(ureport)

        db_opsys = None
        if osr is not None:
            db_opsys = osr.opsys

        osname = ureport["os"]["name"]
        if osname not in systems:
            log.warning("Operating system '%s' is not supported", osname)
        else:
            osplugin = systems[osname]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)
            if db_opsys is None:
                log.warning("Operaring system '%s' is not installed in storage",
                            osplugin.nice_name)
            else:
                pkgname_parsers = self._get_pkgname_parsers(db, db_opsys=db_opsys)
                for parser, solution in pkgname_parsers.items():
                    if osplugin.check_pkgname_match(ureport["packages"], parser):
                        return self._sfps_to_solution(solution)

        ptype = ureport["problem"]["type"]
        if ptype not in problemtypes:
            log.warning("Problem type '%s' is not supported", ptype)
        else:
            problemplugin = problemtypes[ptype]
            btpath_parsers = self._get_btpath_parsers(db, db_opsys=db_opsys)
            for parser, solution in btpath_parsers.items():
                if problemplugin.check_btpath_match(ureport["problem"], parser):
                    return self._sfps_to_solution(solution)

        return None
Esempio n. 22
0
    def run(self, cmdline, db) -> int:
        if cmdline.opsys is None:
            self.log_error("You must specify an operating system")
            return 1

        if not cmdline.opsys in systems:
            self.log_error("Operating system '{0}' does not exist".format(
                cmdline.opsys))
            return 1

        opsys = systems[cmdline.opsys]
        db_opsys = get_opsys_by_name(db, opsys.nice_name)
        if db_opsys is None:
            self.log_error("Operating system '{0}' is not installed".format(
                opsys.nice_name))
            return 1

        db_release = get_osrelease(db, opsys.nice_name, cmdline.opsys_release)
        if db_release is not None:
            self.log_info("Release '{0} {1}' is already defined".format(
                opsys.nice_name, cmdline.opsys_release))
            return 0

        if not cmdline.status in OpSysReleaseStatus.enums:
            self.log_error("Status '{0}' is invalid".format(cmdline.status))
            return 1

        self.log_info("Adding release '{0} {1}'".format(
            opsys.nice_name, cmdline.opsys_release))
        db_release = OpSysRelease()
        db_release.opsys = db_opsys
        db_release.version = cmdline.opsys_release
        db_release.status = cmdline.status
        db.session.add(db_release)

        db.session.flush()

        return 0
Esempio n. 23
0
    def run(self, cmdline, db) -> None:
        if not cmdline.opsys:
            cmdline.opsys = list(systems.keys())

        opsyss = []
        for shortname in cmdline.opsys:
            if shortname not in systems:
                self.log_warn("Operating system '{0}' is not installed".format(
                    shortname))
                continue

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_warn(
                    "Operating system '{0}' is not initialized".format(
                        shortname))
                continue

            opsyss.append((opsys, db_opsys))

        new_associates: Dict[str, AssociatePeople] = {}
        opsyss_len = len(opsyss)
        for i, (opsys, db_opsys) in enumerate(opsyss, start=1):
            self.log_info("[{0} / {1}] Processing {2}".format(
                i, opsyss_len, opsys.nice_name))

            components = get_components_by_opsys(db, db_opsys).all()
            components_len = len(components)
            for j, db_component in enumerate(components, start=1):
                name = db_component.name
                self.log_debug("\t[%d / %d] Processing component '%s'", j,
                               components_len, name)
                try:
                    acls = opsys.get_component_acls(name)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists: Dict[str, List[str]] = {
                    "watchbugzilla": [],
                    "commit": []
                }

                for associate_name, associate_perms in acls.items():
                    for permission, permission_members in acl_lists.items():
                        if associate_perms.get(permission, False):
                            permission_members.append(associate_name)

                for permission, permission_members in acl_lists.items():
                    acl_list_perm_len = len(permission_members)
                    for k, associate in enumerate(permission_members, start=1):
                        self.log_debug(
                            "\t[%d / %d] Processing associate '%s' permission %s",
                            k, acl_list_perm_len, associate, permission)

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info(
                                    "Adding a new associate '{0}'".format(
                                        associate))

                        associates = [
                            a.associates for a in db_component.associates
                            if a.permission == permission
                        ]
                        if db_associate not in associates:
                            db_associate_comp = OpSysComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info(
                                "Assigning associate '{0}' to component "
                                "'{1}' with permission {2}".format(
                                    associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name
                                not in permission_members):
                            db.session.delete(db_associate_comp)
                            self.log_info(
                                "Removing associate '{0}' permission "
                                "{1} from component '{2}'".format(
                                    db_associate_comp.associates.name,
                                    permission, name))

                db.session.flush()
Esempio n. 24
0
File: fedora.py Progetto: xsuchy/faf
 def installed(cls, db):
     return bool(get_opsys_by_name(db, cls.nice_name))
Esempio n. 25
0
    def run(self, cmdline, db) -> int:
        if not cmdline.OPSYS and not cmdline.RELEASE and not cmdline.arch:
            self.log_error("None of the arguments were specified.")
            return 1

        if (cmdline.OPSYS or cmdline.RELEASE) and cmdline.arch:
            self.log_error(
                "Argument --arch not allowed with OPSYS and RELEASE.")
            return 1

        if cmdline.OPSYS and not cmdline.RELEASE:
            self.log_error("Missing RELEASE argument.")
            return 1

        # in case we're using the web UI:
        if not hasattr(cmdline, "dry_run"):
            cmdline.dry_run = False

        if cmdline.OPSYS:
            # nobody will write the full name
            if cmdline.OPSYS == "rhel":
                cmdline.OPSYS = "Red Hat Enterprise Linux"

            # check if operating system is known
            if not get_opsys_by_name(db, cmdline.OPSYS):
                self.log_error(
                    "Selected operating system '%s' is not supported.",
                    cmdline.OPSYS)
                return 1

            self.log_info("Selected operating system: '%s'", cmdline.OPSYS)

            # check if release is known
            opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
            if not opsysrelease:
                self.log_error("Selected release '%s' is not supported.",
                               cmdline.RELEASE)
                return 1

            self.log_info("Selected release: '%s'", cmdline.RELEASE)

            # find all builds, that are assigned to this opsysrelease but none other
            # architecture is missed out intentionally
            all_builds = get_builds_by_opsysrelease_id(db, opsysrelease.id)

            #delete all records, where the opsysrelease.id is present
            query = (db.session.query(BuildOpSysReleaseArch).filter(
                BuildOpSysReleaseArch.opsysrelease_id == opsysrelease.id))

        elif cmdline.arch:
            # check if operating system is known
            architecture = get_arch_by_name(db, cmdline.arch)
            if not architecture:
                self.log_error("Selected architecture '%s' is not supported.",
                               cmdline.arch)
                return 1

            self.log_info("Selected architecture: '%s'", cmdline.arch)

            # find all builds, that are assigned to this arch_id but none other
            all_builds = get_builds_by_arch_id(db, architecture.id)

            #delete all records, where the arch.id is present
            query = (db.session.query(BuildOpSysReleaseArch).filter(
                BuildOpSysReleaseArch.arch_id == architecture.id))

        else:
            self.log_error(
                "Architecture or operating system was not selected.")
            return 1

        self.log_info("%d links will be removed", query.count())
        if cmdline.dry_run:
            self.log_info("Dry run active, removal will be skipped")
        else:
            for build in all_builds:
                for pkg in (db.session.query(Package).filter(
                        Package.build_id == build.build_id).all()):
                    self.delete_package(pkg, cmdline.dry_run)

            query.delete()

        return 0
Esempio n. 26
0
    def run(self, cmdline, db):
        result = set()

        if len(cmdline.opsys) < 1:
            for osname, osplugin in systems.items():
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn(
                        "Operating system '{0}' is not installed".format(
                            osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))
        else:
            for osname in cmdline.opsys:
                if osname not in systems:
                    self.log_warn(
                        "Operating system '{0}' is not supported".format(
                            osname))
                    continue

                osplugin = systems[osname]
                db_opsys = get_opsys_by_name(db, osplugin.nice_name)
                if db_opsys is None:
                    self.log_warn(
                        "Operating system '{0}' is not installed".format(
                            osplugin.nice_name))
                    continue

                result.add((osplugin, db_opsys))

        for osplugin, db_opsys in result:
            db_components = get_components_by_opsys(db, db_opsys)
            components = {}
            for db_component in db_components:
                components[db_component.name] = db_component

            i = 0
            db_builds = osplugin.get_build_candidates(db)
            for db_build in db_builds:
                i += 1

                self.log_info("[{0} / {1}] Processing '{2}'".format(
                    i, len(db_builds), db_build.nevr()))

                comp_name = db_build.base_package_name
                if comp_name not in components:
                    self.log_debug("Component '{0}' not found in operating "
                                   "system '{1}'".format(
                                       comp_name, osplugin.nice_name))
                    continue

                db_component = components[comp_name]

                if any(db_component == bcomp.component
                       for bcomp in db_build.components):
                    self.log_debug("Already assigned")
                    continue

                self.log_info("Assigning to component '{0}'".format(comp_name))
                db_buildcomponent = BuildComponent()
                db_buildcomponent.build = db_build
                db_buildcomponent.component = db_component
                db.session.add(db_buildcomponent)

            db.session.flush()
Esempio n. 27
0
    def run(self, cmdline, db):
        db_solution = get_sf_prefilter_sol(db, cmdline.SOLUTION)

        if db_solution is None:
            self.log_error("Unable to find solution '{0}'"
                           .format(cmdline.SOLUTION))
            return 1

        if cmdline.opsys is not None:
            if cmdline.opsys not in systems:
                self.log_error("Operating system '{0}' is not supported"
                               .format(cmdline.opsys))
                return 1

            osplugin = systems[cmdline.opsys]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)

            if db_opsys is None:
                self.log_error("Operating system '{0}' is not installed "
                               "in storage".format(osplugin.nice_name))
                return 1
        else:
            db_opsys = None

        self.log_info("Adding patterns for '{0}'".format(db_solution.cause))
        if db_opsys is not None:
            self.log_info("Limitting patterns to operating system '{0}'"
                          .format(db_opsys.name))

        for btpath in cmdline.btpath:
            self.log_debug("Processing stacktrace path pattern: {0}"
                           .format(btpath))
            db_btpath = get_sf_prefilter_btpath_by_pattern(db, btpath)
            if db_btpath is not None:
                self.log_debug("Stacktrace path pattern {0} already exists"
                               .format(btpath))
                continue

            try:
                re.compile(btpath)
            except re.error as ex:
                self.log_warn("Stacktrace path pattern {0} can not be "
                              "compiled: {1}".format(btpath, str(ex)))
                continue

            self.log_info("Adding new stacktrace path pattern: {0}"
                          .format(btpath))

            db_btpath = SfPrefilterBacktracePath()
            db_btpath.solution = db_solution
            db_btpath.opsys = db_opsys
            db_btpath.pattern = btpath
            db.session.add(db_btpath)

        for pkgname in cmdline.pkgname:
            self.log_debug("Processing package name pattern: {0}"
                           .format(pkgname))
            db_btpath = get_sf_prefilter_pkgname_by_pattern(db, pkgname)
            if db_btpath is not None:
                self.log_debug("Package name pattern {0} already exists"
                               .format(pkgname))
                continue

            try:
                re.compile(pkgname)
            except re.error as ex:
                self.log_warn("Package name pattern {0} can not be "
                              "compiled: {1}".format(pkgname, str(ex)))
                continue

            self.log_info("Adding new package name pattern: {0}"
                          .format(pkgname))

            db_pkgname = SfPrefilterPackageName()
            db_pkgname.solution = db_solution
            db_pkgname.opsys = db_opsys
            db_pkgname.pattern = pkgname
            db.session.add(db_pkgname)

        db.session.flush()
        return 0
Esempio n. 28
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases
                          if release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error(
                    "Operating system '{0}' is not installed".format(
                        shortname))
                return 1

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_error(
                    "Operating system '{0}' is not initialized".format(
                        shortname))
                return 1

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            for shortname in cmdline.opsys:
                if shortname not in systems:
                    self.log_warn(
                        "Operating system '{0}' is not installed".format(
                            shortname))
                    continue

                opsys = systems[shortname]
                db_opsys = get_opsys_by_name(db, opsys.nice_name)
                if db_opsys is None:
                    self.log_warn(
                        "Operating system '{0}' is not initialized".format(
                            shortname))
                    continue

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

            self.log_info("[{0} / {1}] Processing {2} {3}".format(
                i, len(tasks), opsys.nice_name, db_release.version))

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug(
                    "  [{0} / {1}] Processing component '{2}'".format(
                        j, len(db_release.components), name))
                try:
                    acls = opsys.get_component_acls(name,
                                                    release=db_release.version)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {"watchbugzilla": [], "commit": []}

                for associate in acls.keys():
                    for permission in acl_lists.keys():
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists.keys():
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug(
                            "    [{0} / {1}] Processing associate '{2}' "
                            "permission {3}".format(k,
                                                    len(acl_lists[permission]),
                                                    associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info(
                                    "Adding a new associate '{0}'".format(
                                        associate))

                        associates = [
                            a.associates for a in db_component.associates
                            if a.permission == permission
                        ]
                        if db_associate not in associates:
                            db_associate_comp = OpSysReleaseComponentAssociate(
                            )
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info(
                                "Assigning associate '{0}' to component "
                                "'{1}' with permission {2}".format(
                                    associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name
                                not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info(
                                "Removing associate '{0}' permission "
                                "{1} from component '{2}'".format(
                                    db_associate_comp.associates.name,
                                    permission, name))

                db.session.flush()
Esempio n. 29
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases if
                          release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error("Operating system '{0}' is not installed"
                               .format(shortname))
                return 1

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_error("Operating system '{0}' is not initialized"
                               .format(shortname))
                return 1

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            for shortname in cmdline.opsys:
                if shortname not in systems:
                    self.log_warn("Operating system '{0}' is not installed"
                                  .format(shortname))
                    continue

                opsys = systems[shortname]
                db_opsys = get_opsys_by_name(db, opsys.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not initialized"
                                  .format(shortname))
                    continue

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

            self.log_info("[{0} / {1}] Processing {2} {3}"
                          .format(i, len(tasks), opsys.nice_name,
                                  db_release.version))

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(db_release.components), name))

                acls = opsys.get_component_acls(name,
                                                release=db_release.version)
                k = 0
                for associate in acls:
                    k += 1
                    self.log_debug("    [{0} / {1}] Processing associate '{2}'"
                                   .format(k, len(acls), associate))

                    db_associate = get_associate_by_name(db, associate)
                    if db_associate is None:
                        if associate in new_associates:
                            db_associate = new_associates[associate]
                        else:
                            db_associate = AssociatePeople()
                            db_associate.name = associate
                            db.session.add(db_associate)
                            new_associates[associate] = db_associate

                            self.log_info("Adding a new associate '{0}'"
                                          .format(associate))

                    associates = [a.associates for a in db_component.associates]
                    if db_associate not in associates:
                        db_associate_comp = OpSysReleaseComponentAssociate()
                        db_associate_comp.component = db_component
                        db_associate_comp.associates = db_associate
                        db.session.add(db_associate_comp)

                        self.log_info("Assigning associate '{0}' to component "
                                      "'{1}'".format(associate, name))

                db.session.flush()
Esempio n. 30
0
    def run(self, cmdline, db):
        if not cmdline.opsys:
            cmdline.opsys = list(systems.keys())

        opsyss = []
        for shortname in cmdline.opsys:
            if shortname not in systems:
                self.log_warn("Operating system '{0}' is not installed"
                              .format(shortname))
                continue

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_warn("Operating system '{0}' is not initialized"
                              .format(shortname))
                continue

            opsyss.append((opsys, db_opsys))

        new_associates = {}
        i = 0
        for (opsys, db_opsys) in opsyss:
            i += 1

            self.log_info("[{0} / {1}] Processing {2}"
                          .format(i, len(opsyss), opsys.nice_name))

            j = 0
            components = get_components_by_opsys(db, db_opsys).all()
            for db_component in components:
                j += 1

                name = db_component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(components), name))
                try:
                    acls = opsys.get_component_acls(name)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {
                    "watchbugzilla": [],
                    "commit": []
                }

                for associate in acls:
                    for permission in acl_lists:
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists:
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug("    [{0} / {1}] Processing associate '{2}' "
                                       "permission {3}"
                                       .format(k, len(acl_lists[permission]),
                                               associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info("Adding a new associate '{0}'"
                                              .format(associate))

                        associates = [a.associates for a in db_component.associates
                                      if a.permission == permission]
                        if db_associate not in associates:
                            db_associate_comp = OpSysComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info("Assigning associate '{0}' to component "
                                          "'{1}' with permission {2}"
                                          .format(associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                                and db_associate_comp.associates.name not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info("Removing associate '{0}' permission "
                                          "{1} from component '{2}'"
                                          .format(db_associate_comp.associates.name,
                                                  permission, name))

                db.session.flush()
Esempio n. 31
0
    def run(self, cmdline, db):
        repo = (db.session.query(Repo)
                .filter(Repo.name == cmdline.NAME)
                .first())

        if not repo:
            self.log_error("Repository '{0}' not found"
                           .format(cmdline.NAME))
            return 1

        arch_list = []
        opsys_list = []
        opsysrelease_list = []

        for item_name in cmdline.OPSYS + cmdline.ARCH:
            pos_name, pos_release = self._parser_osrelease(item_name)
            opsysrelease = get_osrelease(db, pos_name, pos_release)
            opsys = get_opsys_by_name(db, item_name)
            arch = get_arch_by_name(db, item_name)

            if not (opsys or arch or opsysrelease):
                #If name is rhel we will search Red Hat Enterprise Linux
                if item_name == "rhel":
                    item_name = "Red Hat Enterprise Linux"
                    opsys = get_opsys_by_name(db, item_name)

                    if not opsys:
                        self.log_error("Item '{0}' not found"
                                       .format(item_name))
                        return 1

                elif pos_name == "rhel":
                    pos_name = "Red Hat Enterprise Linux"
                    opsysrelease = get_osrelease(db, pos_name, pos_release)

                    if not opsysrelease:
                        self.log_error("Item '{0}' not found"
                                       .format(item_name))
                        return 1

                else:
                    self.log_error("Item '{0}' not found"
                                   .format(item_name))
                    return 1

            if opsys:
                opsys_list.append(opsys)
            elif opsysrelease:
                opsysrelease_list.append(opsysrelease)
            else:
                arch_list.append(arch)

        # test if url type correspond with type of repo
        if any('$' in url.url for url in repo.url_list) and opsysrelease_list:
            self.log_error("Assigning operating system with release to "
                           "parametrized repo. Assign only operating system.")
            return 1

        if any('$' not in url.url for url in repo.url_list) and opsys_list:
            self.log_error("Assigning operating system without release to "
                           "non - parametrized repo. Assign operating system"
                           " with release.")
            return 1

        repo.opsys_list += opsys_list
        repo.opsysrelease_list += opsysrelease_list
        repo.arch_list += arch_list

        db.session.flush()

        self.log_info("Assigned '{0}' to {1} operating system(s)"
                      ", {2} operating systems with release(s) and {3} architecture(s)"
                      .format(repo.name, len(opsys_list), len(opsysrelease_list),
                              (len(arch_list))))
Esempio n. 32
0
    def run(self, cmdline, db) -> int:
        repo = (db.session.query(Repo).filter(
            Repo.name == cmdline.REPO).first())

        if not repo:
            self.log_error("Repository '{0}' not found".format(cmdline.REPO))
            return 1

        arch_list = []
        opsys_list = []
        opsysrelease_list = []

        for item_name in cmdline.OPSYS + cmdline.ARCH:
            pos_name, pos_release = self._parser_osrelease(item_name)
            opsysrelease = get_osrelease(db, pos_name, pos_release)
            opsys = get_opsys_by_name(db, item_name)
            arch = get_arch_by_name(db, item_name)

            if not (opsys or arch or opsysrelease):
                #If name is rhel we will search Red Hat Enterprise Linux
                if item_name == "rhel":
                    item_name = "Red Hat Enterprise Linux"
                    opsys = get_opsys_by_name(db, item_name)

                    if not opsys:
                        self.log_error(
                            "Item '{0}' not found".format(item_name))
                        return 1

                elif pos_name == "rhel":
                    pos_name = "Red Hat Enterprise Linux"
                    opsysrelease = get_osrelease(db, pos_name, pos_release)

                    if not opsysrelease:
                        self.log_error(
                            "Item '{0}' not found".format(item_name))
                        return 1

                else:
                    self.log_error("Item '{0}' not found".format(item_name))
                    return 1

            if opsys:
                opsys_list.append(opsys)
            elif opsysrelease:
                opsysrelease_list.append(opsysrelease)
            else:
                arch_list.append(arch)

        # test if url type correspond with type of repo
        if any('$' in url.url for url in repo.url_list) and opsysrelease_list:
            self.log_error("Assigning operating system with release to "
                           "parametrized repo. Assign only operating system.")
            return 1

        if any('$' not in url.url for url in repo.url_list) and opsys_list:
            self.log_error("Assigning operating system without release to "
                           "non - parametrized repo. Assign operating system"
                           " with release.")
            return 1

        repo.opsys_list += opsys_list
        repo.opsysrelease_list += opsysrelease_list
        repo.arch_list += arch_list

        db.session.flush()

        self.log_info(
            "Assigned '{0}' to {1} operating system(s)"
            ", {2} operating systems with release(s) and {3} architecture(s)".
            format(repo.name, len(opsys_list), len(opsysrelease_list),
                   (len(arch_list))))

        return 0
Esempio n. 33
0
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error(
                "Selected operating system '{0}' is not supported.".format(
                    cmdline.OPSYS))
            return 1
        else:
            self.log_info("Selected operating system: '{0}'".format(
                cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported.".format(
                cmdline.RELEASE))
            return 1
        else:
            self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # check if architecture is known
        arch = get_arch_by_name(db, cmdline.ARCH)
        if not arch:
            self.log_error(
                "Selected architecture '{0}' is not supported.".format(
                    cmdline.ARCH))
            return 1
        else:
            self.log_info("Selected architecture: '{0}'".format(cmdline.ARCH))

        # when release-builds argument specified
        if cmdline.released_builds:
            self.log_info("Assigning released builds for '{0} {1}'".format(
                cmdline.OPSYS, cmdline.RELEASE))
            opsys = self._edit_opsys(cmdline.OPSYS)
            if not opsys in systems.keys():
                self.log_error(
                    "There are no known released builds for '{0}'".format(
                        cmdline.OPSYS))
                return 1

            for build in systems[opsys].get_released_builds(cmdline.RELEASE):
                found_build = (db.session.query(Build).filter(
                    Build.base_package_name == build["name"]).filter(
                        Build.version == build["version"]).filter(
                            Build.release == build["release"]).filter(
                                Build.epoch == build["epoch"]).first())

                if found_build:
                    self._add_into_build_opsysrelease_arch(
                        db, found_build, opsysrelease, arch)

        # when expression argument was passed
        if cmdline.expression:
            self.log_info("Selecting builds by expression: '{0}'".format(
                cmdline.expression))
            found_builds = (db.session.query(Build).filter(
                Build.release.like("%{0}".format(cmdline.expression))).all())
            for build in found_builds:
                self._add_into_build_opsysrelease_arch(db, build, opsysrelease,
                                                       arch)

        db.session.flush()
Esempio n. 34
0
 def installed(cls, db):
     return bool(get_opsys_by_name(db, cls.nice_name))
Esempio n. 35
0
    def run(self, cmdline, db):
        db_solution = get_sf_prefilter_sol(db, cmdline.SOLUTION)

        if db_solution is None:
            self.log_error("Unable to find solution '{0}'".format(
                cmdline.SOLUTION))
            return 1

        if cmdline.opsys is not None:
            if cmdline.opsys not in systems:
                self.log_error(
                    "Operating system '{0}' is not supported".format(
                        cmdline.opsys))
                return 1

            osplugin = systems[cmdline.opsys]
            db_opsys = get_opsys_by_name(db, osplugin.nice_name)

            if db_opsys is None:
                self.log_error("Operating system '{0}' is not installed "
                               "in storage".format(osplugin.nice_name))
                return 1
        else:
            db_opsys = None

        self.log_info("Adding patterns for '{0}'".format(db_solution.cause))
        if db_opsys is not None:
            self.log_info(
                "Limitting patterns to operating system '{0}'".format(
                    db_opsys.name))

        for btpath in cmdline.btpath:
            self.log_debug(
                "Processing stacktrace path pattern: {0}".format(btpath))
            db_btpath = get_sf_prefilter_btpath_by_pattern(db, btpath)
            if db_btpath is not None:
                self.log_debug(
                    "Stacktrace path pattern {0} already exists".format(
                        btpath))
                continue

            try:
                re.compile(btpath)
            except re.error as ex:
                self.log_warn("Stacktrace path pattern {0} can not be "
                              "compiled: {1}".format(btpath, str(ex)))
                continue

            self.log_info(
                "Adding new stacktrace path pattern: {0}".format(btpath))

            db_btpath = SfPrefilterBacktracePath()
            db_btpath.solution = db_solution
            db_btpath.opsys = db_opsys
            db_btpath.pattern = btpath
            db.session.add(db_btpath)

        for pkgname in cmdline.pkgname:
            self.log_debug(
                "Processing package name pattern: {0}".format(pkgname))
            db_btpath = get_sf_prefilter_pkgname_by_pattern(db, pkgname)
            if db_btpath is not None:
                self.log_debug(
                    "Package name pattern {0} already exists".format(pkgname))
                continue

            try:
                re.compile(pkgname)
            except re.error as ex:
                self.log_warn("Package name pattern {0} can not be "
                              "compiled: {1}".format(pkgname, str(ex)))
                continue

            self.log_info(
                "Adding new package name pattern: {0}".format(pkgname))

            db_pkgname = SfPrefilterPackageName()
            db_pkgname.solution = db_solution
            db_pkgname.opsys = db_opsys
            db_pkgname.pattern = pkgname
            db.session.add(db_pkgname)

        db.session.flush()
        return 0
Esempio n. 36
0
    def run(self, cmdline, db):
        if len(cmdline.opsys) == 0:
            tasks = []
            for opsys in systems.values():
                releases = get_releases(db, opsys_name=opsys.nice_name)
                tasks += [(opsys, release) for release in releases if
                          release.status != "EOL"]
        elif len(cmdline.opsys) == 1:
            shortname = cmdline.opsys[0]
            if shortname not in systems:
                self.log_error("Operating system '{0}' is not installed"
                               .format(shortname))
                return 1

            opsys = systems[shortname]
            db_opsys = get_opsys_by_name(db, opsys.nice_name)
            if db_opsys is None:
                self.log_error("Operating system '{0}' is not initialized"
                               .format(shortname))
                return 1

            if len(cmdline.opsys_release) < 1:
                tasks = [(opsys, r) for r in db_opsys.releases]
            else:
                tasks = [(opsys, r) for r in db_opsys.releases
                         if r.version in cmdline.opsys_release]
        else:
            tasks = []
            for shortname in cmdline.opsys:
                if shortname not in systems:
                    self.log_warn("Operating system '{0}' is not installed"
                                  .format(shortname))
                    continue

                opsys = systems[shortname]
                db_opsys = get_opsys_by_name(db, opsys.nice_name)
                if db_opsys is None:
                    self.log_warn("Operating system '{0}' is not initialized"
                                  .format(shortname))
                    continue

                tasks += [(opsys, rel) for rel in db_opsys.releases]

        new_associates = {}
        i = 0
        for opsys, db_release in tasks:
            i += 1

            self.log_info("[{0} / {1}] Processing {2} {3}"
                          .format(i, len(tasks), opsys.nice_name,
                                  db_release.version))

            j = 0
            for db_component in db_release.components:
                j += 1

                name = db_component.component.name
                self.log_debug("  [{0} / {1}] Processing component '{2}'"
                               .format(j, len(db_release.components), name))
                try:
                    acls = opsys.get_component_acls(name,
                                                    release=db_release.version)
                except TypeError:
                    self.log_warn("Error getting ACLs.")
                    continue

                acl_lists = {
                    "watchbugzilla": [],
                    "commit": []
                }

                for associate in acls.keys():
                    for permission in acl_lists.keys():
                        if acls[associate].get(permission, False):
                            acl_lists[permission].append(associate)

                for permission in acl_lists.keys():
                    k = 0
                    for associate in acl_lists[permission]:
                        k += 1
                        self.log_debug("    [{0} / {1}] Processing associate '{2}' "
                                       "permission {3}"
                                       .format(k, len(acl_lists[permission]),
                                               associate, permission))

                        db_associate = get_associate_by_name(db, associate)
                        if db_associate is None:
                            if associate in new_associates:
                                db_associate = new_associates[associate]
                            else:
                                db_associate = AssociatePeople()
                                db_associate.name = associate
                                db.session.add(db_associate)
                                new_associates[associate] = db_associate

                                self.log_info("Adding a new associate '{0}'"
                                              .format(associate))

                        associates = [a.associates for a in db_component.associates
                                      if a.permission == permission]
                        if db_associate not in associates:
                            db_associate_comp = OpSysReleaseComponentAssociate()
                            db_associate_comp.component = db_component
                            db_associate_comp.associates = db_associate
                            db_associate_comp.permission = permission
                            db.session.add(db_associate_comp)

                            self.log_info("Assigning associate '{0}' to component "
                                          "'{1}' with permission {2}"
                                          .format(associate, name, permission))

                    for db_associate_comp in db_component.associates:
                        if (db_associate_comp.permission == permission
                            and db_associate_comp.associates.name not in acl_lists[permission]):
                            db.session.delete(db_associate_comp)
                            self.log_info("Removing associate '{0}' permission "
                                          "{1} from component '{2}'"
                                          .format(db_associate_comp.associates.name,
                                                  permission, name))

                db.session.flush()
Esempio n. 37
0
    def run(self, cmdline, db):
        # nobody will write the full name
        if cmdline.OPSYS == "rhel":
            cmdline.OPSYS = "Red Hat Enterprise Linux"

        # check if operating system is known
        if not get_opsys_by_name(db, cmdline.OPSYS):
            self.log_error("Selected operating system '{0}' is not supported."
                           .format(cmdline.OPSYS))
            return 1

        self.log_info("Selected operating system: '{0}'"
                      .format(cmdline.OPSYS))

        # check if release is known
        opsysrelease = get_osrelease(db, cmdline.OPSYS, cmdline.RELEASE)
        if not opsysrelease:
            self.log_error("Selected release '{0}' is not supported."
                           .format(cmdline.RELEASE))
            return 1

        self.log_info("Selected release: '{0}'".format(cmdline.RELEASE))

        # check if architecture is known
        arch = get_arch_by_name(db, cmdline.ARCH)
        if not arch:
            self.log_error("Selected architecture '{0}' is not supported."
                           .format(cmdline.ARCH))
            return 1

        self.log_info("Selected architecture: '{0}'".format(cmdline.ARCH))

        # when release-builds argument specified
        if cmdline.released_builds:
            self.log_info("Assigning released builds for '{0} {1}'"
                          .format(cmdline.OPSYS, cmdline.RELEASE))
            opsys = self._edit_opsys(cmdline.OPSYS)
            if opsys not in systems.keys():
                self.log_error("There are no known released builds for '{0}'"
                               .format(cmdline.OPSYS))
                return 1

            for build in systems[opsys].get_released_builds(cmdline.RELEASE):
                found_build = (db.session.query(Build)
                               .filter(Build.base_package_name == build["name"])
                               .filter(Build.version == build["version"])
                               .filter(Build.release == build["release"])
                               .filter(Build.epoch == build["epoch"])
                               .first())

                if found_build:
                    self._add_into_build_opsysrelease_arch(db, found_build,
                                                           opsysrelease, arch)

        # when expression argument was passed
        if cmdline.expression:
            self.log_info("Selecting builds by expression: '{0}'"
                          .format(cmdline.expression))
            found_builds = (db.session.query(Build)
                            .filter(Build.release.like("%{0}"
                                                       .format(cmdline.expression)))
                            .all())
            for build in found_builds:
                self._add_into_build_opsysrelease_arch(db, build,
                                                       opsysrelease, arch)

        db.session.flush()
        return 0