← Back to team overview

juju-tosca team mailing list archive

Re: About refactoring code to add filter and validation logic to parsing process for tosca template.

 

Zhi,

Thank you, that will be much better. Appreciate you sending that along.

Wayne

On Mon, Sep 29, 2014 at 4:52 AM, Zhi Xiang Zhai <zhzxzhai@xxxxxxxxxx> wrote:

> Hi Wayne,
>   Thanks for your comments. Right now I just got the toscalib package,
> which has parsing logic and validation logic in the *template.py. So I will
> replace my parsing logic that you commented to the toscalib package. If you
> have interesting I would send you the toscalib source code. Now I would
> like to show some validation logic in the following for the toscalib, so
> the toscalib will cover the parsing logic for tosca template and my logic
> will be replaced.
>
>     def _validate_properties(self, template, entitytype):
>         properties = entitytype.get_value(self.PROPERTIES, template)
>         allowed_props = []
>         required_props = []
>         for p in entitytype.properties_def:
>             allowed_props.append(p.name)
>             if p.required:
>                 required_props.append(p.name)
>         if properties:
>             self._common_validate_field(properties, allowed_props,
>                                         'Properties')
>             #make sure it's not missing any property required by a tosca
> type
>             missingprop = []
>             for r in required_props:
>                 if r not in properties.keys():
>                     missingprop.append(r)
>             if missingprop:
>                 raise MissingRequiredFieldError(
>                     what='Properties of template %s' % self.name,
>                     required=missingprop)
>         else:
>             if required_props:
>                 raise MissingRequiredFieldError(
>                     what='Properties of template %s' % self.name,
>                     required=missingprop)
>
>     def _validate_capabilities(self):
>         type_capabilities = self.type_definition.capabilities
>         allowed_caps = []
>         if type_capabilities:
>             for tcap in type_capabilities:
>                 allowed_caps.append(tcap.name)
>         capabilities = self.type_definition.get_value(self.CAPABILITIES,
>                                                       self.entity_tpl)
>         if capabilities:
>             self._common_validate_field(capabilities, allowed_caps,
>                                         'Capabilities')
>
>     def _validate_field(self, template):
>         if not isinstance(template, dict):
>             raise MissingRequiredFieldError(
>                 what='Template %s' % self.name, required=self.TYPE)
>         try:
>             template[self.TYPE]
>         except KeyError:
>             raise MissingRequiredFieldError(
>                 what='Template %s' % self.name, required=self.TYPE)
>
>     def _common_validate_field(self, schema, allowedlist, section):
>         for name in schema:
>             if name not in allowedlist:
>                 raise UnknownFieldError(
>                     what='%(section)s of template %(nodename)s'
>                     % {'section': section, 'nodename': self.name},
>                     field=name)
>
> [image: Inactive hide details for Wayne Witzel ---2014/09/17
> 22:18:18---Thanks for the update. We need to address these areas of the co]Wayne
> Witzel ---2014/09/17 22:18:18---Thanks for the update. We need to address
> these areas of the code either by using toscalib OR refact
>
> From: Wayne Witzel <wayne.witzel@xxxxxxxxxxxxx>
> To: Zhi Xiang Zhai/China/IBM@IBMCN
> Cc: juju-tosca@xxxxxxxxxxxxxxxxxxx
> Date: 2014/09/17 22:18
> Subject: Re: [Juju-tosca] About refactoring code to add filter and
> validation logic to parsing process for tosca template.
> ------------------------------
>
>
>
> Thanks for the update. We need to address these areas of the code either
> by using toscalib OR refactoring the existing code. I really believe pretty
> strongly in the adage, "You won't fix it later". Even with best intentions,
> letting known issues in to a code base results in those issues living for
> much much longer than they should, considering they shouldn't of lived in
> the code at all.
>
> Wayne
>
> On Tue, Sep 16, 2014 at 11:29 PM, Zhi Xiang Zhai <*zhzxzhai@xxxxxxxxxx*
> <zhzxzhai@xxxxxxxxxx>> wrote:
>
>    Hi all,
>       Thanks all of you for your review comments. I addressing all of
>    comments except the comments related to refactoring to add filter and
>    validation logic to parsing process for tosca template from Wayne.  I agree
>    the comment from Wanye and think it should be a good pattern. But as I know
>    the toscalib will be imported to our project, it will be responsible for
>    the parsing process for tosca template, so I suggest we would not refactor
>    the parsing logic since the parsing logic will be done by toscalib.
>    Thanks
>
>    --
>    Mailing list: *https://launchpad.net/~juju-tosca*
>    <https://launchpad.net/~juju-tosca>
>    Post to     : *juju-tosca@xxxxxxxxxxxxxxxxxxx*
>    <juju-tosca@xxxxxxxxxxxxxxxxxxx>
>    Unsubscribe : *https://launchpad.net/~juju-tosca*
>    <https://launchpad.net/~juju-tosca>
>    More help   : *https://help.launchpad.net/ListHelp*
>    <https://help.launchpad.net/ListHelp>
>
>
>
>
> --
> Wayne Witzel III
> *wayne.witzel@xxxxxxxxxxxxx* <wayne.witzel@xxxxxxxxxxxxx>




-- 
Wayne Witzel III
wayne.witzel@xxxxxxxxxxxxx

References