def test_invalid_pipeline_type(self):
        configuration = {"camera_name": "simulation"}
        expanded_configuration = PipelineConfig.expand_config(configuration)
        PipelineConfig.validate_pipeline_config(expanded_configuration)

        expanded_configuration["pipeline_type"] = "invalid"

        with self.assertRaisesRegex(
                ValueError,
                "pipeline_type 'invalid' not present in mapping. Available:"):
            PipelineConfig.validate_pipeline_config(expanded_configuration)
    def test_invalid_number_of_slices(self):
        configuration = {
            "camera_name": "simulation",
            "image_slices": {
                "number_of_slices": 1.2
            }
        }

        expanded_configuration = PipelineConfig.expand_config(configuration)
        with self.assertRaisesRegex(ValueError,
                                    "number_of_slices must be an integer"):
            PipelineConfig.validate_pipeline_config(expanded_configuration)
    def test_store_pipeline_port_requirement(self):
        configuration = {"camera_name": "simulation", "pipeline_type": "store"}
        expanded_configuration = PipelineConfig.expand_config(configuration)

        with self.assertRaisesRegex(ValueError, "stream_port"):
            PipelineConfig.validate_pipeline_config(expanded_configuration)

        configuration = {
            "camera_name": "simulation",
            "pipeline_type": "store",
            "stream_port": "test"
        }
        expanded_configuration = PipelineConfig.expand_config(configuration)

        with self.assertRaisesRegex(ValueError, "must be an integer"):
            PipelineConfig.validate_pipeline_config(expanded_configuration)

        configuration = {
            "camera_name": "simulation",
            "pipeline_type": "store",
            "stream_port": config.PIPELINE_STREAM_PORT_RANGE[0]
        }
        expanded_configuration = PipelineConfig.expand_config(configuration)

        with self.assertRaisesRegex(ValueError, "must be outside of"):
            PipelineConfig.validate_pipeline_config(expanded_configuration)

        configuration = {
            "camera_name": "simulation",
            "pipeline_type": "store",
            "stream_port": config.PIPELINE_STREAM_PORT_RANGE[1] + 1
        }
        expanded_configuration = PipelineConfig.expand_config(configuration)
        PipelineConfig.validate_pipeline_config(expanded_configuration)
예제 #4
0
    def create_pipeline(self, pipeline_name=None, configuration=None, instance_id=None):
        """
        If both pipeline_name and configuration are set, pipeline is create from name and
        configuration field added as additional config parameters
        """
        status = self.get_status()

        if (not pipeline_name) and (not configuration):
            raise ValueError("You must specify either the pipeline name or the configuration for the pipeline.")

        if pipeline_name is not None:
            cfg = self.config_manager.get_pipeline_config(pipeline_name)
        elif configuration is not None:
            cfg = PipelineConfig.expand_config(configuration)
            PipelineConfig.validate_pipeline_config(cfg)

        server,port = None,None
        if instance_id is not None:
            server = self.get_server(instance_id, status)
        if server is None:
            (server,port) = self.get_server_for_pipeline(pipeline_name, cfg, status)
            if port:
                if not configuration:
                    configuration = {}
                configuration["port"] = port

        self._check_background(server, cfg)
        self._check_script(server, cfg)
        if pipeline_name is not None:
            server.save_pipeline_config(pipeline_name, cfg)
            _logger.info("Creating stream from name %s at %s" % (pipeline_name, server.get_address()))
            instance_id, stream_address = server.create_instance_from_name(pipeline_name, instance_id, configuration)
        elif cfg is not None:
            _logger.info("Creating stream from config to camera %s at %s" % (str(cfg.get("camera_name")), server.get_address()))
            instance_id, stream_address = server.create_instance_from_config(cfg, instance_id)
        else:
            raise Exception("Invalid parameters")

        return instance_id, stream_address