Пример #1
0
    def check_if_valid(self):
        """
        Check if a distro object is valid. If invalid an exception is raised.
        """
        if self.name is None:
            raise CX("name is required")
        if self.kernel is None:
            raise CX("Error with distro %s - kernel is required" % (self.name))
        if self.initrd is None:
            raise CX("Error with distro %s - initrd is required" % (self.name))

        # self.remote_grub_kernel has to be set in set_remote_boot_kernel and here
        # in case the distro is read from json file (setters are not called).
        if self.remote_boot_kernel:
            self.remote_grub_kernel = grub.parse_grub_remote_file(self.remote_boot_kernel)
            if not self.remote_grub_kernel:
                raise CX("Invalid URL for remote boot kernel: %s" % self.remote_boot_kernel)
        if self.remote_boot_initrd:
            self.remote_grub_initrd = grub.parse_grub_remote_file(self.remote_boot_initrd)
            if not self.remote_grub_initrd:
                raise CX("Invalid URL for remote boot initrd: %s" % self.remote_boot_initrd)

        if utils.file_is_remote(self.kernel):
            if not utils.remote_file_exists(self.kernel):
                raise CX("Error with distro %s - kernel '%s' not found" % (self.name, self.kernel))
        elif not os.path.exists(self.kernel):
            raise CX("Error with distro %s - kernel '%s' not found" % (self.name, self.kernel))

        if utils.file_is_remote(self.initrd):
            if not utils.remote_file_exists(self.initrd):
                raise CX("Error with distro %s - initrd path '%s' not found" % (self.name, self.initrd))
        elif not os.path.exists(self.initrd):
            raise CX("Error with distro %s - initrd path '%s' not found" % (self.name, self.initrd))
Пример #2
0
    def remote_boot_kernel(self, remote_boot_kernel: str):
        """
        Setter for the ``remote_boot_kernel`` property.

        :param remote_boot_kernel: The new URL to the remote booted kernel.
        :raises TypeError: Raised in case the URL is not of type str.
        :raises ValueError: Raised in case the validation is not succeeding.
        """
        if not isinstance(remote_boot_kernel, str):
            raise TypeError(
                "Field remote_boot_kernel of distro needs to be of type str!")
        if remote_boot_kernel:
            if remote_boot_kernel == "":
                self._remote_boot_kernel = ""
                self._remote_grub_kernel = ""
                return
            if not validate.validate_boot_remote_file(remote_boot_kernel):
                raise ValueError(
                    "remote_boot_kernel needs to be a valid URL starting with tftp or http!"
                )
            parsed_url = grub.parse_grub_remote_file(remote_boot_kernel)
            if parsed_url is None:
                raise ValueError("Invalid URL for remote boot kernel: %s" %
                                 remote_boot_kernel)
            self._remote_grub_kernel = parsed_url
            self._remote_boot_kernel = remote_boot_kernel
            return
        self._remote_grub_kernel = remote_boot_kernel
        self._remote_boot_kernel = remote_boot_kernel
Пример #3
0
def test_parse_grub_remote_file(input_file_location, expected_output,
                                expected_exception):
    # Arrange & Act
    with expected_exception:
        result = grub.parse_grub_remote_file(input_file_location)

        # Assert
        assert result == expected_output
Пример #4
0
 def set_remote_boot_initrd(self, remote_boot_initrd):
     """
     URL to a remote initrd. If the bootloader supports this feature,
     it directly tries to retrieve the initrd and boot it.
     (grub supports tftp and http protocol and server must be an IP).
     """
     if remote_boot_initrd:
         self.remote_grub_initrd = grub.parse_grub_remote_file(remote_boot_initrd)
         if not self.remote_grub_initrd:
             raise CX("Invalid URL for remote boot initrd: %s" % remote_boot_initrd)
         self.remote_boot_initrd = remote_boot_initrd
         return
     # Set to None or ""
     self.remote_grub_initrd = self.remote_boot_initrd = remote_boot_initrd
Пример #5
0
 def set_remote_boot_kernel(self, remote_boot_kernel):
     """
     URL to a remote kernel. If the bootloader supports this feature,
     it directly tries to retrieve the kernel and boot it.
     (grub supports tftp and http protocol and server must be an IP).
     """
     if remote_boot_kernel:
         self.remote_grub_kernel = grub.parse_grub_remote_file(remote_boot_kernel)
         if not self.remote_grub_kernel:
             raise CX("Invalid URL for remote boot kernel: %s" % remote_boot_kernel)
         self.remote_boot_kernel = remote_boot_kernel
         return
     # Set to None or ""
     self.remote_grub_kernel = self.remote_boot_kernel = remote_boot_kernel
Пример #6
0
    def remote_grub_initrd(self, value: str):
        """
        TODO

        :param value:
        """
        if not isinstance(value, str):
            raise TypeError("remote_grub_initrd must be of type str")
        if not value:
            self._remote_grub_initrd = ""
            return
        parsed_url = grub.parse_grub_remote_file(value)
        if parsed_url is None:
            raise ValueError("Invalid URL for remote boot initrd: %s" % value)
        self._remote_grub_initrd = parsed_url
Пример #7
0
 def remote_boot_kernel(self, remote_boot_kernel: str):
     """
     URL to a remote kernel. If the bootloader supports this feature, it directly tries to retrieve the kernel and
     boot it. (grub supports tftp and http protocol and server must be an IP).
     TODO: Obsolete it and merge with kernel property
     """
     if not isinstance(remote_boot_kernel, str):
         raise TypeError(
             "Field remote_boot_kernel of distro needs to be of type str!")
     if remote_boot_kernel:
         parsed_url = grub.parse_grub_remote_file(remote_boot_kernel)
         if parsed_url is None:
             raise ValueError("Invalid URL for remote boot kernel: %s" %
                              remote_boot_kernel)
         self._remote_grub_kernel = parsed_url
         self._remote_boot_kernel = remote_boot_kernel
         return
     self._remote_grub_kernel = remote_boot_kernel
     self._remote_boot_kernel = remote_boot_kernel
Пример #8
0
    def remote_boot_initrd(self, remote_boot_initrd: str):
        """
        The setter for the ``remote_boot_initrd`` property.

        :param remote_boot_initrd: The new value for the property.
        :raises TypeError: In case the value was not of type ``str``.
        :raises ValueError: In case the new value could not be validated successfully.
        """
        if not isinstance(remote_boot_initrd, str):
            raise TypeError("remote_boot_initrd must be of type str!")
        if not remote_boot_initrd:
            self._remote_boot_initrd = remote_boot_initrd
            self._remote_grub_initrd = remote_boot_initrd
            return
        if not validate.validate_boot_remote_file(remote_boot_initrd):
            raise ValueError("remote_boot_initrd needs to be a valid URL starting with tftp or http!")
        parsed_url = grub.parse_grub_remote_file(remote_boot_initrd)
        if parsed_url is None:
            raise ValueError("Invalid URL for remote boot initrd: %s" % remote_boot_initrd)
        self._remote_grub_initrd = parsed_url
        self._remote_boot_initrd = remote_boot_initrd