'Validate the template.
Validates the top-level sections of the template as well as syntax
inside select sections. Some sections are not checked here but in
code parts that are responsible for working with the respective
sections (e.g. parameters are check by parameters schema class).'

def validate(self):

    t_digest = hashlib.sha256(six.text_type(self.t).encode('utf-8')).hexdigest()
    if (t_digest == self.t_digest):
        return
    for k in self.t.keys():
        if (k not in self.SECTIONS):
            raise exception.InvalidTemplateSection(section=k)
    for res in six.itervalues(self[self.RESOURCES]):
        try:
            if ((not res) or (not res.get('Type'))):
                message = _('Each    Resource    must    contain    a    Type    key.')
                raise exception.StackValidationFailed(message=message)
        except AttributeError:
            message = (_('Resources    must    contain    Resource.    Found    a    [%s]    instead') % type(res))
            raise exception.StackValidationFailed(message=message)
    self.t_digest = t_digest
