def copy_single_distro_files(self, d, dirtree, symlink_ok): distros = os.path.join(dirtree, "images") distro_dir = os.path.join(distros, d.name) utils.mkdir(distro_dir) kernel = utils.find_kernel(d.kernel) # full path initrd = utils.find_initrd(d.initrd) # full path if kernel is None: raise CX("kernel not found: %(file)s, distro: %(distro)s" % {"file": d.kernel, "distro": d.name}) if initrd is None: raise CX("initrd not found: %(file)s, distro: %(distro)s" % {"file": d.initrd, "distro": d.name}) # Koan manages remote kernel itself, but for consistent PXE # configurations the synchronization is still necessary if not utils.file_is_remote(kernel): b_kernel = os.path.basename(kernel) dst1 = os.path.join(distro_dir, b_kernel) utils.linkfile(kernel, dst1, symlink_ok=symlink_ok, api=self.api, logger=self.logger) else: b_kernel = os.path.basename(kernel) dst1 = os.path.join(distro_dir, b_kernel) utils.copyremotefile(kernel, dst1, api=None, logger=self.logger) if not utils.file_is_remote(initrd): b_initrd = os.path.basename(initrd) dst2 = os.path.join(distro_dir, b_initrd) utils.linkfile(initrd, dst2, symlink_ok=symlink_ok, api=self.api, logger=self.logger) else: b_initrd = os.path.basename(initrd) dst1 = os.path.join(distro_dir, b_initrd) utils.copyremotefile(initrd, dst1, api=None, logger=self.logger)
def set_initrd(self, initrd): """ Specifies an initrd image. Path search works as in set_kernel. File must be named appropriately. """ if initrd is None or initrd == "": raise CX("initrd not specified") if utils.find_initrd(initrd): self.initrd = initrd return raise CX(_("initrd not found"))
def set_initrd(self, initrd): """ Specifies an initrd image. Path search works as in set_kernel. File must be named appropriately. """ if initrd is None or initrd == "": raise CX("initrd not specified") if utils.find_initrd(initrd): self.initrd = initrd return raise CX(_("initrd not found"))
def test_find_initrd(): # Arrange fake_env = "/dev/shm/fakeinitrdfolder" os.mkdir(fake_env) expected = os.path.join(fake_env, "initrd.img") Path(expected).touch() # Act result = utils.find_initrd(fake_env) # Assert assert expected == result
def initrd(self, initrd: str): """ Specifies an initrd image. Path search works as in set_kernel. File must be named appropriately. :param initrd: The new path to the ``initrd``. """ if not isinstance(initrd, str): raise TypeError("initrd must be of type str") if not initrd: raise ValueError("initrd not specified") if utils.find_initrd(initrd): self._initrd = initrd return raise ValueError("initrd not found")
def initrd(self, initrd: str): r""" Setter for the ``initrd`` property. :param initrd: The new path to the ``initrd``. :raises TypeError: In case the value was not of type ``str``. :raises ValueError: In case the new value was not found or specified. """ if not isinstance(initrd, str): raise TypeError("initrd must be of type str") if not initrd: raise ValueError("initrd not specified") if utils.find_initrd(initrd): self._initrd = initrd return raise ValueError("initrd not found")