def _subdirectory_test(self, pkgs):
        """ Main method for the test, that is called when the test suite is started, does all the work """
        for pkg in pkgs:
            name = os.path.basename(pkg)
            _subpkg = rename_default_subpkg(pkgsplit.get_subpackage_only(name))
            if _subpkg not in self._get_expected_subdirectories(name).keys():
                continue
            if not DefaultMock().postinstall_exception_checked(pkg):
                SubdirectoryTest.instance.log("Skipping subdirectory test for {}".format(_subpkg), vc.Verbosity.TEST)
                continue

            subdirectories = DefaultMock().execute_ls(JVM_DIR)
            if subdirectories[1] != 0:
                passed_or_failed(self, False, "Warning: " + JVM_DIR + " does not exist, skipping subdirectory test for"
                                " given subpackage {}".format(_subpkg))
                continue
            subdirectories = subdirectories[0].split("\n")
            subdirectories = self._remove_fake_subdirectories(subdirectories)
            expected_subdirectories = self._get_expected_subdirectories(name)[_subpkg]
            expected_subdirectories.append(self._get_nvra_suffix(name))
            expected_subdirectories = set(expected_subdirectories)
            SubdirectoryTest.instance.log("Testing subdirectories for {}:".format(name), vc.Verbosity.TEST)
            SubdirectoryTest.instance.log("Expected: " + str(sorted(expected_subdirectories)),
                                          vc.Verbosity.TEST)
            SubdirectoryTest.instance.log("Presented: " + str(sorted(subdirectories)), vc.Verbosity.TEST)
            self._test_subdirectories_equals(subdirectories, expected_subdirectories, _subpkg, name)
            self._test_links_are_correct(subdirectories, name, _subpkg)

        if len(self.list_of_failed_tests) != 0:
            SubdirectoryTest.instance.log("Summary of failed tests: " + "\n        ".join(self.list_of_failed_tests),
                                          vc.Verbosity.ERROR)
        return self.passed, self.failed
Ejemplo n.º 2
0
 def getRpmWholeName(self, pkg, arch):
     defaultrpm = "nonexistent"
     for rpm in self.getPackagesByArch(arch):
         if ns.get_subpackage_only(rpm) == "":
             defaultrpm = rpm
         for suffix in tc.get_debug_suffixes():
             if pkg in rpm and not pkg + suffix in rpm:
                 return rpm
     return defaultrpm.replace("rpms/", "")
    def a_symlink_test(self, pkgs):
        """ This test aggregates all of the checks and excludes into one big check. """
        self._document("All symlinks must have valid target.")
        symlink_dict = {}

        pkgs = SymlinkTest.instance.getBuild()

        DefaultMock().provideCleanUsefullRoot()
        SymlinkTest.instance.log("Getting pre-existing symlinks", vc.Verbosity.TEST)
        default_symlink_list = DefaultMock().executeCommand(["symlinks -rvs /"])[0].split("\n")

        for pkg in pkgs:
            name = os.path.basename(pkg)
            _subpkg = rename_default_subpkg(pkgsplit.get_subpackage_only(name))
            if _subpkg in subpackages_without_alternatives():
                continue
            if not DefaultMock().postinstall_exception_checked(pkg):
                continue

            # iterating over all directories recursively (-r) and under all symlinks (-v)
            symlinks_list = DefaultMock().executeCommand(["symlinks -rvs /"])
            symlinks_list = symlinks_list[0].split("\n")
            symlinks = diff(symlinks_list, default_symlink_list)
            symlink_dict[_subpkg] = self._symlink_parser(symlinks)

        for subpackage in symlink_dict.keys():
            for link in symlink_dict[subpackage]:
                if link.type_of_symlink == SymlinkTypes.DANGLING:
                    SymlinkTest.instance.log("Found dangling link in {}: {}. Further check ongoing, determining whether"
                                             " this is expected behavior.".format(subpackage, link.__str__()),
                                             vc.Verbosity.TEST)
                    # dangling links must be checked for excludes
                    self.check_dangling_symlinks(link, subpackage)

                else:
                    # TODO: Must check if the link does not point on other link, if it does, check whether that one is
                    # TODO: not broken
                    passed_or_failed(self, True, "")
                    SymlinkTest.instance.log("Found valid link in {}: ".format(subpackage) + link.__str__(),
                                              vc.Verbosity.TEST)
        SymlinkTest.instance.log("Failed symlinks tests: " + "\n".join(self.list_of_failed_tests), vc.Verbosity.TEST)
        return self.passed, self.failed
Ejemplo n.º 4
0
    def _get_all_binaries_and_slaves(self, pkgs):

        for pkg in pkgs:
            name = os.path.basename(pkg)
            _subpkg = tu.rename_default_subpkg(
                pkgsplit.get_subpackage_only(name))
            if _subpkg in tc.subpackages_without_alternatives(
            ) + tc.get_javadoc_dirs():
                self.binaries_test.log("Skipping binaries extraction for " +
                                       _subpkg)
                self.skipped.append(_subpkg)
                continue
            if not mexe.DefaultMock().postinstall_exception_checked(pkg):
                self.binaries_test.log(
                    "Failed to execute postinstall. Slaves will not be found for "
                    + _subpkg)
            binary_directory_path = self._get_binary_directory_path(name)
            binaries = mexe.DefaultMock().execute_ls(binary_directory_path)

            if binaries[1] != 0:
                self.binaries_test.log(
                    "Location {} does not exist, binaries test skipped "
                    "for ".format(binary_directory_path) + name,
                    vc.Verbosity.TEST)

                continue
            else:
                self.binaries_test.log(
                    "Binaries found at {}: {}".format(
                        binary_directory_path,
                        ", ".join(binaries[0].split("\n"))), vc.Verbosity.TEST)

            slaves = self.get_slaves(_subpkg)

            self.installed_slaves[_subpkg] = slaves
            self.installed_binaries[_subpkg] = binaries[0].split("\n")

        return self.installed_binaries, self.installed_slaves
Ejemplo n.º 5
0
 def test_checkAllSubpackages(self):
     rpms = self.getBuild()
     subpackages = set()
     for rpm in rpms:
         subpackages.add(split.get_subpackage_only(ntpath.basename(rpm)))
     return self.csch.checkSubpackages(subpackages)
Ejemplo n.º 6
0
    def man_page_test(self, pkgs):
        self._document("Every binary must have a man page. If binary has a slave, then man page has also its slave."
                       " \n - Man pages are in {} directory.".format(tc.MAN_DIR))
        bins = {}
        manpages_without_postscript = {}
        manpages_with_postscript = {}

        mexe.DefaultMock().provideCleanUsefullRoot()
        default_mans = mexe.DefaultMock().execute_ls(tc.MAN_DIR)[0].split("\n")
        usr_bin_content = mexe.DefaultMock().execute_ls("/usr/bin")[0].split("\n")
        plugin_bin_content = mexe.DefaultMock().execute_ls(self._itw_plugin_bin_location())[0].split("\n")

        for pkg in pkgs:
            name = os.path.basename(pkg)
            _subpkg = tu.rename_default_subpkg(pkgsplit.get_subpackage_only(name))
            # expects binaries are only in devel/default/headless subpackage, is consistent with binaries test
            if _subpkg not in self._get_subpackages():
                continue

            # first check links
            if not mexe.DefaultMock().postinstall_exception_checked(pkg):
                self.skipped.append(_subpkg)
                continue
            masters = mexe.DefaultMock().get_masters()

            checked_masters = self._get_checked_masters()

            for m in masters:
                if m not in checked_masters:
                    continue
                tg = self._get_target(m)
                binaries = mexe.DefaultMock().execute_ls(tg)[0].split("\n")
                binaries = self._clean_up_binaries(binaries, m, usr_bin_content)
                binaries = self._remove_java_rmi_cgi(binaries)
                binaries = self._remove_excludes(binaries)
                try:
                    plugin_binaries = self._get_extra_bins(plugin_bin_content)
                except NotADirectoryError:
                    tu.passed_or_failed(self, False, "/usr/bin directory not found, this is unexpected "
                                                  "behaviour and the test will not be executed.")
                    return

                ManpageTests.instance.log("Binaries found for {}: ".format(tg) + ", ".join(binaries + plugin_binaries))
                bins[_subpkg] = copy.deepcopy(binaries + plugin_binaries)

            # check links
            manpages = self._clean_default_mpges(default_mans, mexe.DefaultMock().execute_ls(tc.MAN_DIR)[0].split("\n"))

            if len(manpages) != 0:
                manpages_with_postscript[_subpkg] = manpages
                ManpageTests.instance.log("Manpages found: " + ", ".join(manpages))
            else:
                ManpageTests.instance.log("Warning: {} subpackage does not contain any binaries".format(_subpkg))

            # then check files
            mexe.DefaultMock().importRpm(pkg)
            manpages_without_postscript[_subpkg] = self._clean_default_mpges(default_mans,
                                                                             mexe.DefaultMock().execute_ls(tc.MAN_DIR)[0]
                                                                             .split("\n"))
        try:
            bins = self._clean_sdk_from_jre(bins, self._get_subpackages())
            bins = self.binaries_without_manpages(bins)
        except KeyError as e:
            tu.passed_or_failed(self, False, "This type of failure usually means missing package in tested rpm set."
                                  " Text of the error: " + str(e))

        # then compare man files with binaries and man links with links
        for subpackage in bins.keys():
            manpage_files = self.manpage_file_check(bins, subpackage, plugin_bin_content, manpages_without_postscript)
            self.manpage_links_check(bins, subpackage, manpages_with_postscript, manpage_files)

        self.iced_tea_web_check(manpages_with_postscript, manpages_without_postscript)

        ManpageTests.instance.log("Failed tests summary: " + ", ".join(self.list_of_failed_tests), vc.Verbosity.ERROR)
        return self.passed, self.failed
Ejemplo n.º 7
0
    def doc_test_java_files_permissions(self, pkgs):
        """Main test method body."""
        self._document(
            "On all files extracted from RPMs to {}/nvra and {} apply "
            "following rules:".format(JVM_DIR, MAN_DIR))
        # get default manpages, since we check these too
        DefaultMock().provideCleanUsefullRoot()
        default_manpages, res = DefaultMock().execute_ls(MAN_DIR)
        default_manpages = default_manpages.split("\n")
        passed_or_failed(
            self, res == 0,
            "Default manpages extraction has failed. Manpage tests will be invalid: "
            + str(res) + str(default_manpages))
        for pkg in pkgs:
            name = os.path.basename(pkg)
            subpackage = rename_default_subpkg(
                pkgsplit.get_subpackage_only(name))
            PermissionTest.instance.log(
                "Checking {} subpackage...".format(subpackage),
                vc.Verbosity.TEST)
            if subpackage in subpackages_without_alternatives(
            ) + self._skipped_subpackages():
                PermissionTest.instance.log("Skipping " + pkg,
                                            vc.Verbosity.TEST)
                continue

            if not DefaultMock().postinstall_exception_checked(pkg):
                continue

            # get content of jvm directory
            jvm_dir = self._get_target_java_directory(name)
            out, result = DefaultMock().executeCommand(
                ["ls -LR " + JVM_DIR + "/" + jvm_dir])
            out = out.split("\n")
            fails = []
            clearedout = []
            for line in out:
                if line.startswith("ls: cannot access"):
                    fails.append(line)
                else:
                    clearedout.append(line)
            if len(fails) > 0:
                la.LoggingAccess().log(
                    "Following warning produced while listing files for " +
                    pkg + ":", vc.Verbosity.TEST)
                for line in fails:
                    la.LoggingAccess().log("    " + line)
            if len(clearedout) > 0:
                result = 0
            if not passed_or_failed(
                    self, result == 0, "Java directory not found for " +
                    subpackage + ", for desired directory " + jvm_dir):
                continue
            valid_targets = self._parse_output(clearedout, subpackage)
            self.sort_and_test(valid_targets, subpackage, name)

            manpages = two_lists_diff(
                DefaultMock().execute_ls(MAN_DIR)[0].split("\n"),
                default_manpages)
            for manpage in manpages:
                self.sort_and_test([MAN_DIR + "/" + manpage], subpackage, name)

        PermissionTest.instance.log(
            "Failed permissions tests: " +
            "\n    ".join(self.list_of_failed_tests), vc.Verbosity.ERROR)
        PermissionTest.instance.log(
            "Unexpected files, filetypes or errors occured, requires sanity check, these are "
            "treated as fails: " + "\n    ".join(self.invalid_file_candidates))
        return self.passed, self.failed
    def path_test(self, args=None):
        self._document(
            "All binaries must be on $PATH. If present on multiple paths, the alternatives "
            "links must be equal.")
        path_contents = {}
        pkgs = self.binaries_test.getBuild()
        for pkg in pkgs:
            name = os.path.basename(pkg)
            _subpkg = rename_default_subpkg(pkgsplit.get_subpackage_only(name))
            if _subpkg in subpackages_without_alternatives(
            ) + get_javadoc_dirs():
                self.binaries_test.log("Skipping path test for " + _subpkg)
                continue
            if not DefaultMock().postinstall_exception_checked(pkg):
                self.binaries_test.log(
                    "Skipping path test because of missing post install scriptlet."
                )
                continue
            if (_subpkg == DEFAULT or _subpkg
                    in [DEFAULT + suffix
                        for suffix in get_debug_suffixes()]) and int(
                            pkgsplit.simplify_full_version(
                                pkgsplit.get_minor_ver(name))) >= 10:
                self.binaries_test.log(
                    "Skipping default package, it has no binaries.")
                continue
            if _subpkg == PLUGIN and pkgsplit.get_vendor(name) == "ibm" and \
                     int(pkgsplit.simplify_version(pkgsplit.get_major_ver(name))) == 8 and pkgsplit.get_dist(name) == "el8":
                self.binaries_test.log(
                    "Skipping plugin package, it has no binaries.")
                continue

            paths = self._get_paths()
            self.binaries_test.log("Given paths: " + ", ".join(paths),
                                   vc.Verbosity.TEST)

            for path in paths:
                content = self._get_path_contents(path)
                if content[1] != 0:
                    content = []
                else:
                    content = content[0].split("\n")
                path_contents[path] = content

            self.binaries_test.log(
                "Validating binaries paths for {} subpackage: ".format(
                    _subpkg), vc.Verbosity.TEST)
            if _subpkg in self.installed_binaries:
                for binary in self.installed_binaries[_subpkg]:
                    found_paths = self._binary_in_path_contents(
                        path_contents, binary)
                    if passed_or_failed(
                            self, found_paths is not None, binary +
                            " not found in any path given for " + _subpkg):
                        self.binaries_test.log(
                            "Binary {} found in {} for "
                            "{}".format(binary, ", ".join(found_paths),
                                        _subpkg), vc.Verbosity.TEST)

        self.binaries_test.log("Path test finished.", vc.Verbosity.TEST)
        return
 def test_jreobsolete(self):
     rpms = self.getBuild()
     for pkg in rpms:
         if split.get_subpackage_only(pkg) == '':
             return self.csch._checkJreObsolete(rpmuts.listOfVersionlessObsoletes(pkg))