def allScripletsPReturnsZero(self): pkgs = self.getBuild() failures = [] passes = [] skippes = [] for pkg in pkgs: DefaultMock().importRpm(pkg) # now applying scriplets in order for scriplet in ScripletStarterFinisher.allScriplets: self.log("searching for " + scriplet + " in " + ntpath.basename(pkg)) content = utils.rpmbuild_utils.getSrciplet(pkg, scriplet) if len(content) == 0: self.log(scriplet + " not found in " + ntpath.basename(pkg)) skippes.append(scriplet + " - " + ntpath.basename(pkg)) else: self.log("is " + str(len(content)) + " lines long") self.log("executing " + scriplet + " in " + ntpath.basename(pkg)) o, r = DefaultMock().executeScriptlet(pkg, scriplet) self.log(scriplet + "returned " + str(r) + " of " + ntpath.basename(pkg)) if r == 0: passes.append(scriplet + " - " + ntpath.basename(pkg)) else: failures.append(scriplet + " - " + ntpath.basename(pkg)) for s in skippes: self.log("skipped: " + s) for s in skippes: self.log("passed : " + s) for s in skippes: self.log("failed : " + s) assert len(failures) == 0
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 _test_fill_in(self, file, filetype, expected_permission): """ This method takes as an argument path to a file, type of the file for logs, expected permission and checks, if it matches results from chroot. It also documents any fails or successful checks. """ out, res = DefaultMock().executeCommand(['stat -c "%a" ' + file]) if out == "775" and "ibm" in file: PermissionTest.instance.log( "Skipping " + file + ". Some unzipped Ibm packages are acting wierdly in mock. " "Howewer, in installed JDK, the permissions are correct.", vc.Verbosity.TEST) return if res != 0: passed_or_failed( self, False, filetype + " link is broken, could not find " + file) return else: PermissionTest.instance.log( filetype + " {} exists. Checking permissions... ".format(file), vc.Verbosity.MOCK) for p in range(3): if not (int(out[p]) == int(expected_permission[p])): passed_or_failed( self, False, "Permissions of {} not as expected, should be {} but is " "{}.".format(file, expected_permission, out)) return PermissionTest.instance.log( filetype + " {} with permissions {}. Check " "successful.".format(file, out), vc.Verbosity.MOCK) passed_or_failed(self, True, "") return
def _test_links_are_correct(self, subdirectories, name, _subpkg): """ Tests if all the symlinks in /usr/lib/jvm ('fake subdirectories') are pointing at correct target (usually /usr/lib/jvm/nvr(a)) """ SubdirectoryTest.instance.log("Testing subdirectory links: ") for subdirectory in subdirectories: expected_link = JVM_DIR + "/" + self._get_nvra_suffix(name) # skipping created subdirs at mock init, are dirs, not links if "jce" in subdirectory: SubdirectoryTest.instance.log(subdirectory + " is a directory.") continue if "jre" in subdirectory: expected_link = self._get_jre_link(expected_link) readlink = DefaultMock().executeCommand(["readlink -f {}".format(JVM_DIR + "/" + subdirectory)]) if readlink[1] != 0: passed_or_failed(self, False, subdirectory + " is not a link! Subdirectory test link failed for " + _subpkg) elif readlink[0] != expected_link: passed_or_failed(self, False, " {} should point at {} but points at {} ".format(subdirectory, expected_link, readlink[0])) else: passed_or_failed(self, True, "", "Subdirectory link check successful for " + subdirectory)
def _binary_in_path_contents(self, path_contents, binary): paths = set() for path in path_contents.keys(): if binary in path_contents[path]: paths.add(path) if len(paths) == 0: return None result = set() for p in paths: tg = "readlink " + p + "/" + binary res = DefaultMock().executeCommand([tg]) if passed_or_failed( self, res[1] == 0, "Command readlink " + p + "/" + binary + " failed."): result.add(res) if len(result) != 1: if len(result) > 1: passed_or_failed( self, False, "Links of one binary do not point on same target: " + ",".join(result)) else: passed_or_failed(self, False, "Links do not point on any target.") return paths
def _get_priority(self, master): """ This method calls chroot in mock and gets priority from pre-configured methods. """ priority = DefaultMock().get_priority(master) if priority is None: PriorityCheck.instance.log( "Priority not found in output for master " + master + ", output is invalid.", vc.Verbosity.TEST) return None return priority
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
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
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 sort_and_test(self, valid_targets, subpackage=None, name=None): """ Sorts the files and checks whether permissions are as expected. If ever adding any exclude case, it must be documented in the _document method. """ self._document("\n - ".join([ "Directories should have 755 permissions.", "Content of bin directory should have 755 permissions", "All of the files ending with '.so' should have 755 permissions", "Regular files should have 644 permissions", "Symbolic links should have 777 permissions.", "Permissions of a file classes.jsa must be 444." "Binary jexec and jspawnhelper are exceptions and must be in lib directory and have" " 755 permissions.", "Other types of files with different permissions should not be present." ])) for target in valid_targets: out, res = DefaultMock().executeCommand(['stat -c "%F" ' + target]) if JVM_DIR not in target and MAN_DIR not in target and res == 0: passed_or_failed( self, True, "", "This target: " + target + " is located out of the jvm directory. " "These files are not checked.") continue # this is not easy to reproduce - there is an error in lib directory permissions, but since there is # jre subpackage present along with devel (default or headless), this keeps being hidden # for now we cover it with this hook, but once reproducible, we will ask for official fix # since it behaves correctly so far, this is a PASS # TODO: reproduce and fix if (target == JVM_DIR + "/" + self._get_target_java_directory(name) + "/lib" and "devel" in subpackage): passed_or_failed( self, True, "", target + " in subpackage " + subpackage + ". This is an unknown bug in the" " framework / jre, that is not reproducible " "so far. Howewer, in installed JDK, the permissions are correct." ) continue if out == "directory": self._test_fill_in(target, out, "755") elif out == "regular file" or out == "regular empty file": if "/bin/" in target: self._test_fill_in(target, "binary", "755") elif ".so" in target: self._test_fill_in(target, "file ending with .so", "755") elif "/lib/server/classes.jsa" in target: self._test_fill_in(target, "file classes.jsa", "444") elif "/lib/jexec" in target: self._test_fill_in(target, "binary jexec", "755") elif "/lib/jspawnhelper" in target: self._test_fill_in(target, "binary jspawnhelper", "755") elif target.endswith(".pf") or target.endswith(".data"): self._test_fill_in(target, out, "444") elif target.endswith(".template") and "/conf/" not in target: self._test_fill_in(target, out, "444") else: self._test_fill_in(target, out, "644") elif out == "symbolic link": self._test_fill_in(target, out, "777") out, res = DefaultMock().executeCommand(["readlink " + target]) if not passed_or_failed( self, res == 0, "Target of symbolic link {} does not exist.".format( target) + " Error " + out): continue out = self._get_link_full_path(target, out) self.sort_and_test([out], subpackage, name) else: if res != 0: PermissionTest.instance.log( "Command stat -c '%F' {} finished with {} exit" " code".format(target, res)) # JRE binaries in SDK packages have broken links that result in failed command. if subpackage == DEVEL and ( self._get_target_java_directory(name) + "/jre/bin/") in target: PermissionTest.instance.log( "This is expected behaviour in devel subpackage, since this is " "consciously broken " "symlink to default subpackage binaries. Not treated as fail." ) self.passed += 1 continue else: passed_or_failed( self, False, "In subpackage {} following was found: Command stat -c '%F' {} finished" " with message: {}. ".format( subpackage, target, res, out)) self.invalid_file_candidates.append("Target: " + target + " with result: " + res.__str__() + " and output: " + out) continue else: PermissionTest.instance.log( "Unexpected filetype. Needs manual inspection.", vc.Verbosity.TEST) passed_or_failed( self, False, "In subpackage {} following was found: Command stat -c '%F' {} finished" " with message: {}. ".format(subpackage, target, res, out)) self.invalid_file_candidates.append(target)
def _prepare_for_check(self, pkg): output = True if "plugin" in pkg: output = DefaultMock().postinstall_exception_checked( pkg.replace("plugin", "webstart")) return DefaultMock().postinstall_exception_checked(pkg) and output
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 _prepare_for_check(self, pkg): return DefaultMock().postinstall_exception_checked(pkg)
def _get_path_contents(self, path): content = DefaultMock().execute_ls(path) return content
def _get_paths(self): paths = DefaultMock().executeCommand(["echo $PATH"]) if paths[1] != 0: raise MockExecutionException("Command echo $PATH failed.") paths = paths[0].split(os.pathsep) return paths
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