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
    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.º 3
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.º 4
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.º 5
0
    def _check_post_in_script(self, pkgs=None):
        """
        This method executes post install script and then looks for masters in /var/lib/alternatives. Checks whether
        it matches expected set of masters, that is generated for each JDK.
        """
        passed = []
        failed = []

        # skipped should contain only subpackages that does not have postscript
        skipped = []

        # we need to delete the already existing masters so we get only the installed ones
        _default_masters = DefaultMock().get_default_masters()

        # correct set of masters
        expected_masters = self._generate_masters()

        # masters installed in mock
        actual_masters = {}

        for pkg in pkgs:
            _subpackage = rename_default_subpkg(
                utils.pkg_name_split.get_subpackage_only(
                    os.path.basename(pkg)))

            PostinstallScriptTest.instance.log(
                "Searching for " + rbu.POSTINSTALL + " in " +
                os.path.basename(pkg), vc.Verbosity.TEST)
            PostinstallScriptTest.instance.log(
                "Checking master for " + os.path.basename(pkg),
                vc.Verbosity.TEST)
            if "-debuginfo" in _subpackage:
                PostinstallScriptTest.instance.log(
                    "Skipping " + _subpackage +
                    " subpackage, because debuginfo "
                    "subpackages does not contain "
                    "any postinstall.")
                continue
            if not DefaultMock().postinstall_exception_checked(pkg):
                skipped.append(_subpackage)
                continue
            pkg_masters = DefaultMock().get_masters()

            for m in _default_masters:
                pkg_masters.remove(m)

            actual_masters[_subpackage] = pkg_masters

        PostinstallScriptTest.instance.log(
            "Postinstall script does not exist for: " + str(skipped) + ".",
            vc.Verbosity.TEST)
        PostinstallScriptTest.instance.log(
            "Postinstall expected in " + str(len(expected_masters)) + " : " +
            ", ".join(expected_masters), vc.Verbosity.TEST)
        PostinstallScriptTest.instance.log(
            "Postinstall present in " + str(len(actual_masters)) + " : " +
            ", ".join(actual_masters), vc.Verbosity.TEST)
        passed_or_failed(
            self,
            set(expected_masters.keys()) == set(actual_masters.keys()),
            "expected subpkgs do not match actual ones: " +
            str(expected_masters.keys()) + " != " + str(actual_masters.keys()))
        for subpkg in expected_masters.keys():
            if not passed_or_failed(
                    self, subpkg in actual_masters.keys(),
                    "There is no such subpackage as " + subpkg +
                    " that contains masters."):
                continue
            PostinstallScriptTest.instance.log(
                "Expected masters for " + subpkg + " : " +
                ", ".join(sorted(expected_masters[subpkg])), vc.Verbosity.TEST)
            PostinstallScriptTest.instance.log(
                "Presented masters for " + subpkg + " : " +
                ", ".join(sorted(actual_masters[subpkg])), vc.Verbosity.TEST)
            passed_or_failed(
                self,
                sorted(expected_masters[subpkg]) == sorted(
                    actual_masters[subpkg]),
                "expected masters do not match actual ones for {}: ".format(
                    subpkg) + str(sorted(expected_masters[subpkg])) + " != " +
                str(sorted(actual_masters[subpkg])))

        return self.passed, self.failed
Ejemplo n.º 6
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
Ejemplo n.º 7
0
    def _check_priorities(self, pkgs):

        _default_masters = DefaultMock().get_default_masters()

        # stores a dict of {pkg_name : {master : priority }}
        _pkgPriorities = {}

        for pkg in pkgs:
            pkg_name = rename_default_subpkg(
                utils.pkg_name_split.get_subpackage_only(
                    os.path.basename(pkg)))

            if pkg_name in subpackages_without_alternatives():
                PriorityCheck.instance.log(
                    pkg +
                    " is not expected to contain postscript, skipping check.")
                continue

            # must be here anyway, since it creates the snapshot
            if not self._prepare_for_check(pkg):
                # logs itself in mock
                continue

            _pkgPriorities[pkg_name] = {}

            masters = DefaultMock().get_masters()
            for m in masters:
                #ignoring libjavaplugin as Jvanek stated is unnecessary for us to check on.
                if m in _default_masters or LIBJAVAPLUGIN in m:
                    continue
                try:
                    priority = self._get_priority(m)
                except utils.mock.mock_execution_exception.MockExecutionException as e:
                    passed_or_failed(self, False, str(e))
                    if "failed " not in str(e):
                        raise e
                if priority is None:
                    PriorityCheck.instance.log(
                        "Failed to get priority, skipping check for " + m +
                        " in " + pkg_name)
                    continue

                if (self.check_length(priority)
                        and self.check_prefix(priority)):
                    self._success_list.append(os.path.basename(pkg))
                    PriorityCheck.instance.log(
                        "Priority " + priority + " valid for " + pkg_name +
                        " package, master " + m, vc.Verbosity.TEST)

                    _pkgPriorities[pkg_name].update({m: priority})

                else:
                    passed_or_failed(
                        self, False, "Priority " + priority + " invalid for " +
                        os.path.basename(pkg) + " package, master " + m)

        PriorityCheck.instance.log("Checking debug packages priorities.",
                                   vc.Verbosity.TEST)
        self.check_debug_packages(_pkgPriorities)
        PriorityCheck.instance.log(
            "Successful for: " + str(self._success_list), vc.Verbosity.TEST)
        PriorityCheck.instance.log(
            "Failed for: " + str(self.list_of_failed_tests),
            vc.Verbosity.ERROR)
        PriorityCheck.instance.log(
            "Debug package priority check failed for: " +
            str(self._debug_check_fail_list), vc.Verbosity.ERROR)
        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