예제 #1
0
def translate_file(from_file, logger):
    """
    Returns a Python dictionary representation of the from_file argument.

    If from_file is a string, the assumption taken is that it's the name
    of a JSON file. In that case, the verify_file_exists(file_name) method
    will be called on it, first. That method returns a Jython File object,
    which is what this translate_file(from_file) method works with.

    :param from_file: A File
    :param logger: A PlatformLogger instance that will be used for logging
                   any exceptions that are thrown
    :return: A Python dictionary representation of the from_file argument
    :raises: TestingException: if a TranslateException is caught during the translation
    """
    _method_name = 'translate_file'

    try:
        if isinstance(from_file, str):
            from_file = verify_file_exists(from_file, logger)

        from_file_dict = FileToPython(from_file.getAbsolutePath(),
                                      True).parse()
    except TranslateException, te:
        ex = exception_helper.create_testing_exception(
            'WLSDPLY-09807',
            from_file.getAbsolutePath(),
            te.getLocalizedMessage(),
            error=te)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
예제 #2
0
def _apply_overrides_file(overrides_file_name, test_def_dict, logger):
    _method_name = '_apply_overrides_file'

    try:
        variable_map = variables.load_variables(overrides_file_name)
        variables.substitute(test_def_dict, variable_map)
    except VariableException, ve:
        ex = exception_helper.create_testing_exception('WLSDPLY-09814',
                                                       overrides_file_name,
                                                       ve.getLocalizedMessage(), error=ve)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
예제 #3
0
def __import_module(modules_path, module_name, logger):
    """

    :param modules_path:
    :param module_name:
    :param logger: A PlatformLogger instance that will be used for logging
                   any exceptions that are thrown
    :return:
    """
    _method_name = 'import_module'

    fp = None

    try:
        fp, pathname, description = imp.find_module(module_name,
                                                    [modules_path])
    except ImportError:
        if fp is not None:
            fp.close()
        exctype, value = sys.exc_info()[:2]
        ex = exception_helper.create_testing_exception('WLSDPLY-09822',
                                                       module_name, str(value))
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex

    try:
        _module = imp.load_module(module_name, fp, pathname, description)
        fp.close()
    except Exception:
        if fp is not None:
            fp.close()
        exctype, value = sys.exc_info()[:2]
        ex = exception_helper.create_testing_exception('WLSDPLY-09822',
                                                       module_name, str(value))
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex

    return _module
예제 #4
0
def apply_substitution_variables_file(variable_file, model_dict, logger):
    _method_name = 'apply_substitution_variables_file'

    if variable_file is None:
        return

    try:
        variable_map = variables.load_variables(variable_file)
        variables.substitute(model_dict, variable_map)
    except VariableException, ve:
        ex = exception_helper.create_testing_exception('WLSDPLY-09814',
                                                       variable_file,
                                                       ve.getLocalizedMessage(), error=ve)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
예제 #5
0
def verify_file_exists(file_name, logger):
    """

    :param file_name:
    :param logger: A PlatformLogger instance that will be used for logging
                   any exceptions that are thrown
    :return:
    """
    _method_name = 'verify_file_exists'

    try:
        j_file = FileUtils.validateExistingFile(file_name)
    except IllegalArgumentException, iae:
        ex = exception_helper.create_testing_exception(
            'WLSDPLY-09808', file_name, iae.getLocalizedMessage(), error=iae)
        logger.throwing(ex, class_name=_class_name, method_name=_method_name)
        raise ex
예제 #6
0
    def run_stage(self, stage, test_def):
        """
        Runs the given '''stage''' which is associated with the given '''test_def''' object.

        If this is a test definition for a testing_constants.SYSTEM_TEST, then the
        stage will have the following parameters:

            TestDefStage.STEP_NAMES_FILE
                The name of the JSON file that contains the step names for the stage.

            TestDefStage.STEP_NAMES
                A Python list containing the step (or test method) name of a stage. A stage
                is actually a class that extends unittest.TestCase, so step names are essentially
                the names of the methods in that class.

        :param stage: A TestDefStage object associated with the test definition file
        :param test_def: A TestDef object that contains the stages for the test
        :return: TestResult object created when running the stage
        :raises TestingException: if a TestingException is raised while running the test
        :raises SystemTestException: if a SystemTestException is raised while running the test
        :raises IntegrationTestException: if a IntegrationTestException is raised while running the test
        """
        _method_name = 'run_stage'

        self._logger.entering(class_name=_class_name, method_name=_method_name)

        if stage is None:
            ex = exception_helper.create_testing_exception('WLSDPLY-09862')
            self._logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
            raise ex

        stage_module = self.get_stage_module(stage)
        test_result = self.__run_stage(stage_module, stage, test_def)

        self._logger.exiting(class_name=_class_name, method_name=_method_name)

        return test_result
예제 #7
0
    def get_stage_module(self, stage):
        """
        Returns the Python module associated with the given stage.

        Getting a stage's module is not generally something that needs to be exposed, but
        the verification test type is an exception. For example, a TestDefVerifier needs to
        create and run a verification test, in order to verify that a TestDef is conformant
        with the test config metadata for it. Like all other test types, the steps in this
        verification test are defined in a stage module, but here the TestDefVerifier needs to
        run the stage steps on the TestDef, not asks a StageRunner to do it. Making this
        a public method allows that use case to be supported.

        The module and class name parameters are set on the passed in stage object, using
        information from the stages map that was created when the stages map JSON file was
        loaded.

        :param stage: A TestDefStage object
        :return: The Python module associated with a given stage
        :raises: TestingException: if there is problem obtaining the stage's Python module
        """
        _method_name = 'get_stage_module'

        if stage is None:
            ex = exception_helper.create_testing_exception('WLSDPLY-09862')
            self._logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
            raise ex

        stage_name = stage.get_name()

        if stage_name not in self._stages_map:
            ex = exception_helper.create_testing_exception(
                'WLSDPLY-09806', stage_name)
            self._logger.throwing(ex,
                                  class_name=_class_name,
                                  method_name=_method_name)
            raise ex

        module_name = self._stages_map[stage_name][TestDefStage.MODULE_NAME]
        class_name = self._stages_map[stage_name][TestDefStage.CLASS_NAME]

        self._logger.finer('module_name={0}, class_name={1}',
                           module_name,
                           class_name,
                           class_name=_class_name,
                           method_name=_method_name)

        if stage_name in self._stage_modules_cache:
            self._logger.fine('WLSDPLY-09817',
                              stage_name,
                              class_name=_class_name,
                              method_name=_method_name)
            stage_module = self._stage_modules_cache[stage_name]
        else:
            self._logger.fine('WLSDPLY-09818',
                              stage_name,
                              class_name=_class_name,
                              method_name=_method_name)
            stage_module = testing_helper.import_stage_module(
                module_name, self._logger)

        stage.set_module_name(module_name)
        stage.set_class_name(class_name)

        return stage_module