def test_os_release(): # Arrange # TODO: Make this nicer so it doesn't need to run on suse specific distros to succeed. # Act result = utils.os_release() # Assert assert ("suse", 15.2) or ("suse", 15.3) == result
def _generate_iso(self, xorrisofs_opts: str, iso: str, buildisodir: str): """ Build the final xorrisofs command which is then executed on the disk. :param xorrisofs_opts: The additional options for xorrisofs. :param iso: The name of the output iso. :param buildisodir: The directory in which we build the ISO. """ running_on, _ = utils.os_release() if running_on in ("suse", "centos", "virtuozzo", "redhat"): isohdpfx_location = pathlib.Path( self.api.settings().syslinux_dir).joinpath("isohdpfx.bin") else: isohdpfx_location = pathlib.Path( self.api.settings().syslinux_dir).joinpath("mbr/isohdpfx.bin") efi_img_location = "grub/grub.efi" cmd_list = [ "xorriso", "-as", "mkisofs", xorrisofs_opts, "-isohybrid-mbr", str(isohdpfx_location), "-c", "isolinux/boot.cat", "-b", "isolinux/isolinux.bin", "-no-emul-boot", "-boot-load-size", "4", "-boot-info-table", "-eltorito-alt-boot", "-e", efi_img_location, "-no-emul-boot", "-isohybrid-gpt-basdat", "-V", '"COBBLER_INSTALL"', "-o", iso, buildisodir, ] cmd = " ".join(cmd_list) xorrisofs_return_code = utils.subprocess_call(cmd, shell=True) if xorrisofs_return_code != 0: self.logger.error("xorrisofs failed with non zero exit code!") return self.logger.info("ISO build complete") self.logger.info("You may wish to delete: %s", buildisodir) self.logger.info("The output file is: %s", iso)
def update_permissions(self, repo_path): """ Verifies that permissions and contexts after an rsync are as expected. Sending proper rsync flags should prevent the need for this, though this is largely a safeguard. """ # all_path = os.path.join(repo_path, "*") owner = "root:apache" (dist, _) = os_release() if dist == "suse": owner = "root:www" elif dist in ("debian", "ubuntu"): owner = "root:www-data" cmd1 = "chown -R " + owner + " %s" % repo_path utils.subprocess_call(self.logger, cmd1) cmd2 = "chmod -R 755 %s" % repo_path utils.subprocess_call(self.logger, cmd2)
def __init__(self, is_cobblerd=False): """ Constructor """ # FIXME: this should be switchable through some simple system self.__dict__ = CobblerAPI.__shared_state self.perms_ok = False if not CobblerAPI.__has_loaded: if os.path.exists("/etc/cobbler/use.couch"): self.use_couch = True else: self.use_couch = False # NOTE: we do not log all API actions, because # a simple CLI invocation may call adds and such # to load the config, which would just fill up # the logs, so we'll do that logging at CLI # level (and remote.py web service level) instead. random.seed() self.is_cobblerd = is_cobblerd try: self.logger = clogger.Logger("/var/log/cobbler/cobbler.log") except CX: # return to CLI/other but perms are not valid # perms_ok is False return # FIXME: conslidate into 1 server instance self.selinux_enabled = utils.is_selinux_enabled() self.dist = utils.check_dist() self.os_version = utils.os_release() CobblerAPI.__has_loaded = True # load the modules first, or nothing else works... module_loader.load_modules() self._collection_mgr = collection_manager.CollectionManager(self) self.deserialize() # import signatures try: utils.load_signatures(self.settings().signature_path) except Exception as e: self.log("Failed to load signatures from %s: %s" % (self.settings().signature_path, e)) return self.log("%d breeds and %d OS versions read from the signature file" % ( len(utils.get_valid_breeds()), len(utils.get_valid_os_versions())) ) self.authn = self.get_module_from_file( "authentication", "module", "authn_configfile" ) self.authz = self.get_module_from_file( "authorization", "module", "authz_allowall" ) # FIXME: pass more loggers around, and also see that those # using things via tasks construct their own yumgen/tftpgen # versus reusing this one, which has the wrong logger # (most likely) for background tasks. self.yumgen = yumgen.YumGen(self._collection_mgr) self.tftpgen = tftpgen.TFTPGen(self._collection_mgr, logger=self.logger) self.power_mgr = power_manager.PowerManager(self, self._collection_mgr) self.logger.debug("API handle initialized") self.perms_ok = True
def __init__(self, is_cobblerd=False): """ Constructor """ # FIXME: this should be switchable through some simple system self.__dict__ = CobblerAPI.__shared_state self.perms_ok = False if not CobblerAPI.__has_loaded: # NOTE: we do not log all API actions, because # a simple CLI invocation may call adds and such # to load the config, which would just fill up # the logs, so we'll do that logging at CLI # level (and remote.py web service level) instead. random.seed() self.is_cobblerd = is_cobblerd try: self.logger = clogger.Logger("/var/log/cobbler/cobbler.log") except CX: # return to CLI/other but perms are not valid # perms_ok is False return # FIXME: conslidate into 1 server instance self.selinux_enabled = utils.is_selinux_enabled() self.dist = utils.check_dist() self.os_version = utils.os_release() CobblerAPI.__has_loaded = True # load the modules first, or nothing else works... module_loader.load_modules() self._collection_mgr = collection_manager.CollectionManager(self) self.deserialize() # import signatures try: utils.load_signatures(self.settings().signature_path) except Exception as e: self.log("Failed to load signatures from %s: %s" % (self.settings().signature_path, e)) return self.log("%d breeds and %d OS versions read from the signature file" % ( len(utils.get_valid_breeds()), len(utils.get_valid_os_versions())) ) self.authn = self.get_module_from_file( "authentication", "module", "authn_configfile" ) self.authz = self.get_module_from_file( "authorization", "module", "authz_allowall" ) # FIXME: pass more loggers around, and also see that those # using things via tasks construct their own yumgen/tftpgen # versus reusing this one, which has the wrong logger # (most likely) for background tasks. self.yumgen = yumgen.YumGen(self._collection_mgr) self.tftpgen = tftpgen.TFTPGen(self._collection_mgr, logger=self.logger) self.power_mgr = power_manager.PowerManager(self, self._collection_mgr) self.logger.debug("API handle initialized") self.perms_ok = True