[PATCH] Add support for doing a liveimg kickstart with local file (#1140358)

Samantha N. Bueno sbueno+anaconda at redhat.com
Tue Nov 11 19:24:34 UTC 2014


On Tue, Nov 04, 2014 at 02:15:49PM -0800, Brian C. Lane wrote:
> When using a local file as the disk image it doesn't need to be
> downloaded. Use it directly and decrease the amount of estimated space
> for the installation.

With the "error = None" line Gene added in one of his following
responses, this looks ok to me.

> 
> eg. liveimg --url=file:///run/install/repo/disk.img
> 
> --- Thanks for the patch Gene, give this one a try. It uses the file in place
> --- but uses mostly the same code paths as the network case.
> ---
>  pyanaconda/packaging/livepayload.py | 67 +++++++++++++++++++++++++++----------
>  1 file changed, 49 insertions(+), 18 deletions(-)
> 
> diff --git a/pyanaconda/packaging/livepayload.py b/pyanaconda/packaging/livepayload.py
> index d6db00b..c660ef6 100644
> --- a/pyanaconda/packaging/livepayload.py
> +++ b/pyanaconda/packaging/livepayload.py
> @@ -233,12 +233,10 @@ class LiveImageKSPayload(LiveImagePayload):
>          """ Return True if the url ends with a tar suffix """
>          return any(self.data.method.url.endswith(suffix) for suffix in TAR_SUFFIX)
>  
> -    def setup(self, storage, instClass):
> -        """ Check the availability and size of the image.
> +    def _setup_url_image(self):
> +        """ Check to make sure the url is available and estimate the space
> +            needed to download and install it.
>          """
> -        # This is on purpose, we don't want to call LiveImagePayload's setup method.
> -        ImagePayload.setup(self, storage, instClass)
> -
>          self._proxies = {}
>          if self.data.method.proxy:
>              try:
> @@ -252,6 +250,12 @@ class LiveImageKSPayload(LiveImagePayload):
>          error = None
>          try:
>              req = urllib.urlopen(self.data.method.url, proxies=self._proxies)
> +
> +            # At this point we know we can get the image and what its size is
> +            # Make a guess as to minimum size needed:
> +            # Enough space for image and image * 3
> +            if req.info().get("content-length"):
> +                self._min_size = int(req.info().get("content-length")) * 4
>          except IOError as e:
>              log.error("Error opening liveimg: %s", e)
>              error = e
> @@ -261,26 +265,38 @@ class LiveImageKSPayload(LiveImagePayload):
>              if method.startswith("http") and req.getcode() != 200:
>                  error = "http request returned %s" % req.getcode()
>  
> +        return error
> +
> +    def _setup_file_image(self):
> +        """ Check to make sure the file is available and estimate the space
> +            needed to install it.
> +        """
> +        if not os.path.exists(self.data.method.url[7:]):
> +            return "file does not exist: %s" % self.data.method.url
> +
> +        self._min_size = os.stat(self.data.method.url[7:])[stat.ST_SIZE] * 3
> +        return None
> +
> +    def setup(self, storage, instClass):
> +        """ Check the availability and size of the image.
> +        """
> +        # This is on purpose, we don't want to call LiveImagePayload's setup method.
> +        ImagePayload.setup(self, storage, instClass)
> +
> +        if self.data.method.url.startswith("file://"):
> +            error = self._setup_file_image()
> +        else:
> +            error = self._setup_url_image()
> +
>          if error:
>              exn = PayloadInstallError(str(error))
>              if errorHandler.cb(exn) == ERROR_RAISE:
>                  raise exn
>  
> -        # At this point we know we can get the image and what its size is
> -        # Make a guess as to minimum size needed:
> -        # Enough space for image and image * 3
> -        if req.info().get("content-length"):
> -            self._min_size = int(req.info().get("content-length")) * 4
> -
>          log.debug("liveimg size is %s", self._min_size)
>  
> -    def preInstall(self, *args, **kwargs):
> -        """ Download image and loopback mount it.
> -
> -            This is called after partitioning is setup, we now have space
> -            to grab the image. Download it to sysroot and provide feedback
> -            during the download (using urlgrabber callback).
> -        """
> +    def _preInstall_url_image(self):
> +        """ Download the image using urlgrabber """
>          # Setup urlgrabber and call back to download image to sysroot
>          progress = URLGrabberProgress()
>          ugopts = {"ssl_verify_peer": not self.data.method.noverifyssl,
> @@ -301,6 +317,21 @@ class LiveImageKSPayload(LiveImagePayload):
>                  error = "Failed to download %s, file doesn't exist" % self.data.method.url
>                  log.error(error)
>  
> +    def preInstall(self, *args, **kwargs):
> +        """ Get image and loopback mount it.
> +
> +            This is called after partitioning is setup, we now have space to
> +            grab the image. If it is a network source Download it to sysroot
> +            and provide feedback during the download (using urlgrabber
> +            callback).
> +
> +            If it is a file:// source then use the file directly.
> +        """
> +        if self.data.method.url.startswith("file://"):
> +            self.image_path = self.data.method.url[7:]
> +        else:
> +            error = self._preInstall_url_image()
> +
>          if error:
>              exn = PayloadInstallError(str(error))
>              if errorHandler.cb(exn) == ERROR_RAISE:
> -- 
> 1.9.3
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches


More information about the anaconda-patches mailing list