Beispiel #1
0
def test_validate_uncompleted_config(data, reset_port):
    """ Test a valid but uncompleted toskose config. """

    with tempfile.TemporaryDirectory() as tmp_dir:
        manifest_path = helpers.compute_manifest_path(
            tmp_dir,    # also un pack the csar archive
            data['csar_path'])

        model = ToscaParser().build_model(manifest_path)
        ConfigValidator().validate_config(
            data['uncompleted_toskose_config'],
            tosca_model=model)
Beispiel #2
0
def test_config_validation(data):
    """ Test a valid toskose configuration. """

    with tempfile.TemporaryDirectory() as tmp_dir:
        manifest_path = helpers.compute_manifest_path(
            tmp_dir,    # also un pack the csar archive
            data['csar_path'])

        model = ToscaParser().build_model(manifest_path)
        ConfigValidator().validate_config(
                data['toskose_config'],
                tosca_model=model)
Beispiel #3
0
def test_toskose_config_missing_docker_section(data, reset_port):
    """ Test an invalid toskose config with a missing docker section """

    with tempfile.TemporaryDirectory() as tmp_dir:
        manifest_path = helpers.compute_manifest_path(
            tmp_dir,    # also un pack the csar archive
            data['csar_path'])

        model = ToscaParser().build_model(manifest_path)
        with pytest.raises(ValidationError):
            ConfigValidator().validate_config(
                data['missing_docker_toskose_config'],
                tosca_model=model)
Beispiel #4
0
def test_toskose_config_missing_node(data, reset_port):
    """ Test a toskose config with a missing node.

    Docker data about the missing node is asked to the user.
    """

    with tempfile.TemporaryDirectory() as tmp_dir:
        manifest_path = helpers.compute_manifest_path(
            tmp_dir,    # also un pack the csar archive
            data['csar_path'])

        model = ToscaParser().build_model(manifest_path)
        ConfigValidator().validate_config(
            data['missing_node_toskose_config'],
            tosca_model=model)
Beispiel #5
0
    def toskosed(self, csar_path,
                 config_path=None, output_path=None, enable_push=False):
        """
        Entrypoint for the "toskoserization" process.

        Args:
            csar_path (str): The path to the TOSCA CSAR archive.
            config_path (str): The path to the Toskose configuration file.
            output_path (str): The path to the output directory.
            enable_push (bool): Enable/Disable the auto-pushing of toskosed
                images to Docker Registries.
        Returns:
            The docker-compose file representing the TOSCA-based application.
        """

        if not os.path.exists(csar_path):
            raise ValueError('The CSAR file {} doesn\'t exists'.format(
                csar_path))
        if config_path is not None:
            if not os.path.exists(config_path):
                raise ValueError(
                    'The configuration file {} doesn\'t exists'.format(
                        config_path))
        if output_path is None:
            logger.info('No output path detected. \
                A default output path will be generated.')
            output_path = Toskoserizator._generate_output_path()
        if not os.path.exists(output_path):
            raise ValueError('The output path {} doesn\'t exists'.format(
                output_path))

        csar_metadata = validate_csar(csar_path)

        # temporary dir for unpacking data from .CSAR archive
        # temporary dir for building docker images
        with tempfile.TemporaryDirectory() as tmp_dir_context:
            with tempfile.TemporaryDirectory() as tmp_dir_csar:
                try:
                    unpack_archive(csar_path, tmp_dir_csar)
                    manifest_path = os.path.join(
                        tmp_dir_csar,
                        csar_metadata['Entry-Definitions'])

                    model = ToscaParser().build_model(manifest_path)

                    if config_path is None:
                        config_path = generate_default_config(model)
                    else:
                        ConfigValidator().validate_config(
                            config_path,
                            tosca_model=model)

                        # try to auto-complete config (if necessary)
                        config_path = generate_default_config(
                            model,
                            config_path=config_path)

                    toskose_model(model, config_path)
                    build_app_context(tmp_dir_context, model)

                    for container in model.containers:
                        if container.is_manager:
                            logger.info('Detected [{}] node [manager].'.format(
                                container.name))
                            template = ToskosingProcessType.TOSKOSE_MANAGER
                        elif container.hosted:
                            # if the container hosts sw components
                            # then it need to be toskosed
                            logger.info('Detected [{}] node.'.format(
                                container.name))
                            template = ToskosingProcessType.TOSKOSE_UNIT
                        else:
                            # the container doesn't host any sw component,
                            # left untouched
                            continue

                        ctx_path = os.path.join(
                            tmp_dir_context,
                            model.name,
                            container.name)

                        self._docker_manager.toskose_image(
                            src_image=container.image.name,
                            src_tag=container.image.tag,
                            dst_image=container.toskosed_image.name,
                            dst_tag=container.toskosed_image.tag,
                            context=ctx_path,
                            process_type=template,
                            app_name=model.name,
                            toskose_image=container.toskosed_image.base_name,
                            toskose_tag=container.toskosed_image.base_tag,
                            enable_push=enable_push
                        )

                    generate_compose(
                        tosca_model=model,
                        output_path=output_path,
                    )

                    self.quit()

                except Exception as err:
                    logger.error(err)
                    raise FatalError(
                        CommonErrorMessages._DEFAULT_FATAL_ERROR_MSG)
Beispiel #6
0
def test_schema_metadata():
    assert ConfigValidator().get_schema_metadata() == ['title', 'description']