[virt-tools-list] [virt-manager] [PATCH v2 2/8] create: Validate input on container bootstrap

Cole Robinson crobinso at redhat.com
Mon Jul 10 19:12:32 UTC 2017


On 07/05/2017 12:51 PM, Radostin Stoyanov wrote:
> - Show error if source URL is not provided.
> - Require password for authentication to source registry when username
>   is provided.
> - Show error if destination path is not directory.
> - Show error if the user has no write permissions to destination path.
> - Show Yes/No dialog if the destination directory is not empty.
> ---
>  virtManager/create.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/virtManager/create.py b/virtManager/create.py
> index af90eec..20880da 100644
> --- a/virtManager/create.py
> +++ b/virtManager/create.py
> @@ -20,6 +20,7 @@
>  
>  import logging
>  import pkgutil
> +import os
>  import threading
>  import time
>  
> @@ -1271,6 +1272,30 @@ class vmmCreate(vmmGObjectUI):
>          return self._get_config_install_page() in [INSTALL_PAGE_CONTAINER_APP,
>                                                     INSTALL_PAGE_CONTAINER_OS,
>                                                     INSTALL_PAGE_VZ_TEMPLATE]
> +
> +
> +    def _get_config_oscontainer_bootstrap(self):
> +        return self.widget("install-oscontainer-bootstrap").get_active()
> +
> +
> +    def _get_config_oscontainer_source_url(self):
> +        return (self.widget("install-oscontainer-source-url-entry")
> +                    .get_text().strip())
> +
> +
> +    def _get_config_oscontainer_source_username(self):
> +        return (self.widget("install-oscontainer-source-user")
> +                    .get_text().strip())
> +
> +
> +    def _get_config_oscontainer_source_password(self):
> +        return self.widget("install-oscontainer-source-passwd").get_text()
> +
> +
> +    def _get_config_oscontainer_isecure(self):
> +        return self.widget("install-oscontainer-source-insecure").get_active()
> +
> +
>      def _should_skip_disk_page(self):
>          return self._get_config_install_page() in [INSTALL_PAGE_IMPORT,
>                                                     INSTALL_PAGE_CONTAINER_APP,
> @@ -1953,6 +1978,41 @@ class vmmCreate(vmmGObjectUI):
>              if not fs:
>                  return self.err.val_err(_("An OS directory path is required."))
>  
> +            if self._get_config_oscontainer_bootstrap():
> +

Extra whitespace here

> +                src_url = self._get_config_oscontainer_source_url()
> +                user = self._get_config_oscontainer_source_username()
> +                passwd = self._get_config_oscontainer_source_password()
> +
> +                # Check if the source path was provided
> +                if not src_url:
> +                    return self.err.val_err(_("Source URL is required"))
> +
> +                # Require username and password when authenticate
> +                # to source registry.
> +                if user and not passwd:
> +                    return self.err.val_err(_("Please specify password "
> +                                              "for accessing source registry"))
> +
> +                # Validate destination path
> +                if os.path.exists(fs):
> +                    if not os.path.isdir(fs):
> +                        return self.err.val_err(_("Destination path "
> +                                                  "is not directory: " + fs))

You can't put the variable inside the _() translation function, so you should do:

_("Destination path is not a directory: %s") % fs

> +                    if not os.access(fs, os.W_OK):
> +                        return self.err.val_err(_("No write permissions for "
> +                                                  "directory path: " + fs))
> +                    if os.listdir(fs) != []:
> +                        # Show Yes/No dialog if the destination is not empty
> +                        res = self.err.yes_no(
> +                            _("OS root directory is not empty"),
> +                            _("Creating root file system in not empty "
> +                              "directory might fail due to file conflicts.\n"
> +                              "Would you like to contanue?"))
> +                        if not res:
> +                            return False
> +
> +
>          elif instmethod == INSTALL_PAGE_VZ_TEMPLATE:
>              instclass = virtinst.ContainerInstaller
>              template = self.widget("install-container-template").get_text()
> 

I fixed those bits and pushed this, and patch #1

Thanks,
Cole




More information about the virt-tools-list mailing list