[rhinstaller/blivet/pulls/71 master] Consolidate common code in DeviceFormat class methods.

vpodzime installerbot-noreply at redhat.com
Wed Apr 8 07:31:30 UTC 2015


> @@ -375,21 +384,56 @@ def create(self, **kwargs):
>          if not os.path.exists(self.device):
>              raise FormatCreateError("invalid device specification", self.device)
>  
> +        if self.exists:
> +            raise DeviceFormatError("format already exists")
> +
> +        if self.status:
> +            raise DeviceFormatError("device exists and is active")
> +
> +    # pylint: disable=unused-argument
> +    def _create(self, **kwargs):
> +        """ Type-specific create method. """
> +        pass
> +
> +    # pylint: disable=unused-argument
> +    def _postCreate(self, **kwargs):
> +        self.exists = True
> +        self.notifyKernel()
> +
>      def destroy(self, **kwargs):
>          """ Remove the formatting from the associated block device.
>  
>              :raises: FormatDestroyError
>              :returns: None.
>          """
> -        # pylint: disable=unused-argument
>          log_method_call(self, device=self.device,
>                          type=self.type, status=self.status)
> +        self._preDestroy(**kwargs)
> +        try:
> +            self._destroy(**kwargs)
> +        except Exception:
> +            raise
> +        self._postDestroy(**kwargs)
> +
> +    # pylint: disable=unused-argument
> +    def _preDestroy(self, **kwargs):
> +        if not self.exists:
> +            raise DeviceFormatError("format has not been created")
> +
> +        if self.status:
> +            raise DeviceFormatError("device is active")
> +
> +        if not os.access(self.device, os.W_OK):
> +            raise DeviceFormatError("device path does not exist")

The error message could be more precise -- *"...not exist or is not writable"*

-- 
To view this pull request on github, visit https://github.com/rhinstaller/blivet/pull/71#discussion_r27948267


More information about the anaconda-patches mailing list