[Kimchi-devel] [PATCH][Kimchi 3/6] Fix checking duplicate template before creating it

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Wed Mar 23 13:50:03 UTC 2016


Nice catch to check if the template already exists a little bit early
than current code. But I guess would be better if you do the check in
the beginning of the method, preventing the execution of all unnecessary
process the method does and will not be used.

What do you think?

On 03/22/2016 04:20 PM, Ramon Medeiros wrote:
> Template was being check if duplicated after calling for VMTemplate,
> which can make unecessary work. Check it before creating the class.
> 
> Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
> ---
>  model/templates.py | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/model/templates.py b/model/templates.py
> index 92705b6..b49ac50 100644
> --- a/model/templates.py
> +++ b/model/templates.py
> @@ -72,8 +72,11 @@ class TemplatesModel(object):
>                  raise InvalidParameter("KCHTMPL0003E", {'network': net_name,
>                                                          'template': name})
>          # Creates the template class with necessary information
> -        # Checkings will be done while creating this class, so any exception
> -        # will be raised here
> +        # template with the same name already exists: raise exception
> +        with self.objstore as session:
> +            if name in session.get_list('template'):
> +                raise InvalidOperation("KCHTMPL0001E", {'name': name})
> +
>          t = LibvirtVMTemplate(params, scan=True, conn=self.conn)
> 
>          # Validate cpu info
> @@ -93,8 +96,6 @@ class TemplatesModel(object):
>          name = params['name']
>          try:
>              with self.objstore as session:
> -                if name in session.get_list('template'):
> -                    raise InvalidOperation("KCHTMPL0001E", {'name': name})
>                  session.store('template', name, t.info,
>                                get_kimchi_version())
>          except InvalidOperation:
> 




More information about the Kimchi-devel mailing list