Merge "Update heat-translator requirement"
authorjulien zhang <zhang.jun3g@zte.com.cn>
Sun, 10 Sep 2017 14:47:26 +0000 (14:47 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Sun, 10 Sep 2017 14:47:26 +0000 (14:47 +0000)
setup.py
tools/parser_install.sh [moved from tests/parser_install.sh with 99% similarity]
tosca2heat/heat-translator/setup.cfg
tosca2heat/heat-translator/setup.py
tosca2heat/tosca-parser/setup.py
tosca2heat/tosca-parser/toscaparser/elements/capabilitytype.py
tosca2heat/tosca-parser/toscaparser/elements/statefulentitytype.py
tosca2heat/tosca-parser/toscaparser/parameters.py
tosca2heat/tosca-parser/toscaparser/shell.py
tosca2heat/tosca-parser/toscaparser/tosca_template.py

index c53ce4f..0546aa8 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -1,10 +1,54 @@
+import os
 import setuptools
 
+from distutils.command.install_data import install_data
+from setuptools.command.build_py import build_py
+from setuptools.command.install import install
+
 try:
     import multiprocessing  # noqa
 except ImportError:
     pass
 
+
+class Parser_build_py(build_py):
+    """Override build_py to call customized build."""
+
+    def run(self):
+        print(" ===  Before nfv parser build === ")
+        # self.run_command('xxx')
+        super(Parser_build_py, self).run()
+        print(" ===  After nfv parser build === ")
+
+
+class Parser_install(install):
+    """Override install to call customized install."""
+
+    def run(self):
+        print(" ===  Before nfv parser install === ")
+        super(Parser_install, self).run(self)
+        # Custom stuff here
+        # distutils.command.install actually has some nice helper methods
+        # and interfaces. I strongly suggest reading the docstrings.
+        print(" === After nfv parser install === ")
+
+
+class Parser_post_install(install_data):
+    """Override install_data to call customized install_data."""
+
+    def run(self):
+        print(" === Before nfv parser post install data === ")
+        # Call parent
+        super(Parser_post_install, self).run(self)
+        # Execute commands
+        print(" === After nfv parser post install data ===")
+
+
 setuptools.setup(
     setup_requires=['pbr>=2.0.0'],
+    cmdclass={
+        "build_py": Parser_build_py,
+        "install_data": Parser_install,
+        "post_install": Parser_post_install,
+    },
     pbr=True)
similarity index 99%
rename from tests/parser_install.sh
rename to tools/parser_install.sh
index 40b61d4..d03bbb8 100755 (executable)
@@ -33,9 +33,9 @@ pip uninstall -y heat-translator
 
 # install parser
 if [ -n "${OPNFV_REPO_DIR}" ]; then
-    cd ${OPNFV_REPO_DIR}/parser/tosca2heat/tosca-parser && python setup.py install
     cd ${OPNFV_REPO_DIR}/parser/tosca2heat/heat-translator && python setup.py install
+    cd ${OPNFV_REPO_DIR}/parser/tosca2heat/tosca-parser && python setup.py install
 else
-    cd ${BASE_WORK_DIR}/../tosca2heat/tosca-parser && python setup.py install
     cd ${BASE_WORK_DIR}/../tosca2heat/heat-translator && python setup.py install
+    cd ${BASE_WORK_DIR}/../tosca2heat/tosca-parser && python setup.py install
 fi
\ No newline at end of file
index 863b97d..2a10811 100644 (file)
@@ -1,5 +1,5 @@
 [metadata]
-name = heat-translator
+name = nfv-heattranslator
 version =
 url = https://wiki.opnfv.org/display/parser
 summary = Tool to translate non-heat templates to Heat Orchestration Template in nfv.
index 566d844..bf9aa00 100644 (file)
 # limitations under the License.
 
 # THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
+import os
 import setuptools
 
+from distutils.command.install_data import install_data
+from setuptools.command.build_py import build_py
+from setuptools.command.install import install
+
 # In python < 2.7.4, a lazy loading of package `pbr` will break
 # setuptools if some other modules registered functions in `atexit`.
 # solution from: http://bugs.python.org/issue15881#msg170215
@@ -24,6 +29,48 @@ try:
 except ImportError:
     pass
 
+
+class HeatTranslator_build_py(build_py):
+    """Override build_py to call customized build."""
+
+    def run(self):
+        print(" ===  Before nfv heat translator build === ")
+        # self.run_command('xxx')
+        super(HeatTranslator_build_py, self).run()
+        print(" ===  After nfv heat heat translator build === ")
+
+
+class HeatTranslator_install(install):
+    """Override install to call customized install."""
+
+    def run(self):
+        print(" ===  Before nfv heat translator install === ")
+        # Make sure uninstall toscaparser from openstack
+        os.system("pip uninstall -y heat-translator")
+
+        super(HeatTranslator_install, self).run(self)
+        # Custom stuff here
+        # distutils.command.install actually has some nice helper methods
+        # and interfaces. I strongly suggest reading the docstrings.
+        print(" === After nfv heat translator install === ")
+
+
+class HeatTranslator_post_install(install_data):
+    """Override install_data to call customized install_data."""
+
+    def run(self):
+        print(" === Before nfv heat translator post install data === ")
+        # Call parent
+        super(HeatTranslator_post_install, self).run(self)
+        # Execute commands
+        print(" === After nfv heat translator post install data ===")
+
+
 setuptools.setup(
     setup_requires=['pbr>=2.0.0'],
+    cmdclass={
+        "build_py": HeatTranslator_build_py,
+        "install_data": HeatTranslator_install,
+        "post_install": HeatTranslator_post_install,
+    },
     pbr=True)
index 566d844..3d70b81 100644 (file)
 # limitations under the License.
 
 # THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
+import os
 import setuptools
 
+from distutils.command.install_data import install_data
+from setuptools.command.build_py import build_py
+from setuptools.command.install import install
+
 # In python < 2.7.4, a lazy loading of package `pbr` will break
 # setuptools if some other modules registered functions in `atexit`.
 # solution from: http://bugs.python.org/issue15881#msg170215
+
+
 try:
     import multiprocessing  # noqa
 except ImportError:
     pass
 
+
+class Toscaparser_build_py(build_py):
+    """Override build_py to call customized build."""
+
+    def run(self):
+        print(" ===  Before nfv toscaparser build === ")
+        # self.run_command('xxx')
+        super(Toscaparser_build_py, self).run()
+        print(" ===  After nfv toscaparser build === ")
+
+
+class Toscaparser_install(install):
+    """Override install to call customized install."""
+
+    def run(self):
+        print(" ===  Before nfv toscaparser install === ")
+        # Make sure uninstall toscaparser from openstack
+        os.system("pip uninstall -y tosca-parser")
+
+        super(Toscaparser_install, self).run(self)
+        # Custom stuff here
+        # distutils.command.install actually has some nice helper methods
+        # and interfaces. I strongly suggest reading the docstrings.
+        print(" === After nfv toscaparser install === ")
+
+
+class Toscaparser_post_install(install_data):
+    """Override install_data to call customized install_data."""
+
+    def run(self):
+        print(" === Before nfv toscaparser post install data === ")
+        # Call parent
+        super(Toscaparser_post_install, self).run(self)
+        # Execute commands
+        print(" === After nfv toscaparser post install data ===")
+
+
 setuptools.setup(
     setup_requires=['pbr>=2.0.0'],
+    cmdclass={
+        "build_py": Toscaparser_build_py,
+        "install_data": Toscaparser_install,
+        "post_install": Toscaparser_post_install,
+    },
     pbr=True)
index 5fa9661..23c5afc 100644 (file)
@@ -25,7 +25,7 @@ class CapabilityTypeDef(StatefulEntityType):
         self.nodetype = ntype
         self.properties = None
         self.custom_def = custom_def
-        if self.PROPERTIES in self.defs:
+        if self.defs and self.PROPERTIES in self.defs:
             self.properties = self.defs[self.PROPERTIES]
         self.parent_capabilities = self._get_parent_capabilities(custom_def)
 
index 2f221b3..28ee697 100644 (file)
@@ -46,7 +46,8 @@ class StatefulEntityType(EntityType):
             elif custom_def and entitytype in list(custom_def.keys()):
                 self.defs = custom_def[entitytype]
             else:
-                self.defs = None
+                # avoid errors if self.defs = none
+                self.defs = {}
                 ExceptionCollector.appendException(
                     InvalidTypeError(what=entitytype))
         self.type = entitytype
index 0e24b99..d2d2eb3 100644 (file)
@@ -92,7 +92,7 @@ class Input(object):
         elif EntityType.DATATYPE_NETWORK_PREFIX + self.type in tosca:
             datatype = tosca[EntityType.DATATYPE_NETWORK_PREFIX + self.type]
         elif self.type in self.custom_defs:
-            datatype = self.custom_defs[self.type]
+            datatype = self.custom_defs
 
         DataEntity.validate_datatype(self.type, value, None, datatype)
 
index f669e27..ba9c28f 100644 (file)
@@ -53,55 +53,70 @@ class ParserShell(object):
                             required=True,
                             help=_('YAML template or CSAR file to parse.'))
 
-        parser.add_argument('-nrpv', dest='no_required_paras_valid',
+        parser.add_argument('-nrpv', dest='no_required_paras_check',
                             action='store_true', default=False,
                             help=_('Ignore input parameter validation '
                                    'when parse template.'))
 
+        parser.add_argument('--debug', dest='debug_mode',
+                            action='store_true', default=False,
+                            help=_('debug mode for print more details '
+                                   'other than raise exceptions when '
+                                   'errors happen as possible'))
+
         return parser
 
     def main(self, argv):
         parser = self.get_parser(argv)
         (args, extra_args) = parser.parse_known_args(argv)
         path = args.template_file
-        nrpv = args.no_required_paras_valid
+        nrpv = args.no_required_paras_check
+        debug = args.debug_mode
+
         if os.path.isfile(path):
-            self.parse(path, no_req_paras_valid=nrpv)
+            self.parse(path, no_required_paras_check=nrpv, debug_mode=debug)
         elif toscaparser.utils.urlutils.UrlUtils.validate_url(path):
-            self.parse(path, False, no_req_paras_valid=nrpv)
+            self.parse(path, False,
+                       no_required_paras_check=nrpv,
+                       debug_mode=debug)
         else:
             raise ValueError(_('"%(path)s" is not a valid file.')
                              % {'path': path})
 
-    def parse(self, path, a_file=True, no_req_paras_valid=False):
-        output = None
-        tosca = None
+    def parse(self, path, a_file=True, no_required_paras_check=False,
+              debug_mode=False):
+        nrpv = no_required_paras_check
         try:
             tosca = ToscaTemplate(path, None, a_file,
-                                  no_required_paras_valid=no_req_paras_valid)
+                                  no_required_paras_check=nrpv,
+                                  debug_mode=debug_mode)
         except ValidationError as e:
             msg = _('  ===== main service template ===== ')
             log.error(msg)
             log.error(e.message)
-            raise e
-
-        version = tosca.version
-        if tosca.version:
+            if debug_mode:
+                print(msg)
+                print(e.message)
+            else:
+                raise e
+
+        version = tosca.version if tosca else "unknown"
+        if tosca and tosca.version:
             print("\nversion: " + version)
 
-        if hasattr(tosca, 'description'):
+        if tosca and hasattr(tosca, 'description'):
             description = tosca.description
             if description:
                 print("\ndescription: " + description)
 
-        if hasattr(tosca, 'inputs'):
+        if tosca and hasattr(tosca, 'inputs'):
             inputs = tosca.inputs
             if inputs:
                 print("\ninputs:")
                 for input in inputs:
                     print("\t" + input.name)
 
-        if hasattr(tosca, 'nodetemplates'):
+        if tosca and hasattr(tosca, 'nodetemplates'):
             nodetemplates = tosca.nodetemplates
             if nodetemplates:
                 print("\nnodetemplates:")
@@ -120,7 +135,7 @@ class ParserShell(object):
                         for trigger in policy.triggers:
                             print("\ttrigger name:" + trigger.name)'''
 
-        if hasattr(tosca, 'outputs'):
+        if tosca and hasattr(tosca, 'outputs'):
             outputs = tosca.outputs
             if outputs:
                 print("\noutputs:")
index c961941..c9be9dd 100644 (file)
@@ -69,7 +69,8 @@ class ToscaTemplate(object):
     '''Load the template data.'''
     def __init__(self, path=None, parsed_params=None, a_file=True,
                  yaml_dict_tpl=None, sub_mapped_node_template=None,
-                 no_required_paras_valid=False):
+                 no_required_paras_check=False,
+                 debug_mode=False):
         if sub_mapped_node_template is None:
             ExceptionCollector.start()
         self.a_file = a_file
@@ -79,7 +80,9 @@ class ToscaTemplate(object):
         self.sub_mapped_node_template = sub_mapped_node_template
         self.nested_tosca_tpls_with_topology = {}
         self.nested_tosca_templates_with_topology = []
-        self.no_required_paras_valid = no_required_paras_valid
+        self.no_required_paras_check = no_required_paras_check
+        self.debug_mode = debug_mode
+
         if path:
             self.input_path = path
             self.path = self._get_path(path)
@@ -244,16 +247,20 @@ class ToscaTemplate(object):
                         deepcopy(ExceptionCollector.collecting)
                     nested_template = None
                     try:
-                        nrpv = self.no_required_paras_valid
+                        nrpv = self.no_required_paras_check
                         nested_template = ToscaTemplate(
                             path=fname, parsed_params=parsed_params,
                             sub_mapped_node_template=nodetemplate,
-                            no_required_paras_valid=nrpv)
+                            no_required_paras_check=nrpv)
                     except ValidationError as e:
                         msg = _('  ===== nested service template ===== ')
                         log.error(msg)
                         log.error(e.message)
-                        raise e
+                        if self.debug_mode:
+                            print(msg)
+                            print(e.message)
+                        else:
+                            raise e
 
                     ExceptionCollector.exceptions = deepcopy(cache_exeptions)
                     ExceptionCollector.collecting = \
@@ -312,21 +319,26 @@ class ToscaTemplate(object):
 
     def verify_template(self):
         if ExceptionCollector.exceptionsCaught():
-            if self.no_required_paras_valid:
+            if self.no_required_paras_check:
                 ExceptionCollector.removeException(
                     MissingRequiredParameterError)
 
             if self.input_path:
-                raise ValidationError(
+                exceptions = ValidationError(
                     message=(_('\nThe input "%(path)s" failed validation with '
                                'the following error(s): \n\n\t')
                              % {'path': self.input_path}) +
                     '\n\t'.join(ExceptionCollector.getExceptionsReport()))
             else:
-                raise ValidationError(
+                exceptions = ValidationError(
                     message=_('\nThe pre-parsed input failed validation with '
                               'the following error(s): \n\n\t') +
                     '\n\t'.join(ExceptionCollector.getExceptionsReport()))
+            if not self.debug_mode:
+                raise exceptions
+            else:
+                print(exceptions.message)
+            log.error(exceptions.message)
         else:
             if self.input_path:
                 msg = (_('The input "%(path)s" successfully passed '