def test_save():

    config = get_test_config()

    source_id = "test_add"
    result = config_sources.save(source_id, {
        "uri": source_id,
        "type": "video",
        "live": True,
    })

    assert result["id"] == source_id
    source1 = config_manager.get()["sources"][source_id]
    assert config_manager.get()["sources"][source_id]
    assert source1["uri"] == source_id
Example #2
0
def _configure(env_work_dir=None):
    """Load configuration settings.

    :returns config dict if configuration was loaded without issues.
            None or a specific exception otherwise.
    """
    assert env_work_dir, 'Working directory required.'
    assert os.path.exists(env_work_dir), \
        'working directory invalid: {}'.format(env_work_dir)

    config_manager.stop()

    def logging_config_handler(config):
        # configure logging
        logging_config = None
        if config:
            logging_config = config.get('logging', None)
        _configure_logging(logging_config)

    config_manager.register_handler(logging_config_handler)

    def timeline_config_handler(config):
        # configure pipeline timeline event log
        timeline_config = None
        if config:
            timeline_config = config.get('timeline', None)
        timeline.configure_timeline(timeline_config)

    config_manager.register_handler(timeline_config_handler)

    config_manager.load(env_work_dir)

    return config_manager.get()
def test_pipeline_reload_delete_source_ref():
    """Test that when a source reference changes, the pipeline reload"""
    interpreter.PIPELINE_CLASS = _TestPipeline
    config_manager.stop()
    config_manager.set({
        "sources": {
            "source1": {
                "uri": "test",
                "type": "video",
                "live": False
            }
        },
        "pipelines": {
            "pipeline1": [{
                "source": "source1"
            }]
        }
    })
    config = config_manager.get()
    p = _one_pipeline_setup(config.get("pipelines"))
    p[0].start()

    pe = p[0]._pipe_elements[0]
    assert p[0]._pipe_elements[0].state == pipeline.PIPE_STATE_RUNNING
    assert pe.start_called

    del config["sources"]["source1"]

    assert p[0].restart_called
    assert len(p[0]._pipe_elements) == 0
def test_pipeline_reload_sources_ref():
    """Test that when a source reference changes, the pipeline reload"""
    config_manager.stop()
    config_manager.set({
        "sources": {
            "source1": {
                "uri": "test",
                "type": "video",
                "live": False
            }
        },
        "pipelines": {
            "pipeline1": [{
                "source": "source1"
            }]
        }
    })
    config = config_manager.get()
    p = _one_pipeline_setup(config.get("pipelines"))
    p[0].start()

    pe = p[0]._pipe_elements[0]
    assert p[0]._pipe_elements[0].state == pipeline.PIPE_STATE_RUNNING
    assert pe.start_called

    config["sources"]["source1"]["uri"] = "test2"
    log.debug(p[0]._pipe_elements[0].config)
    assert p[0]._pipe_elements[0].config['uri'] == 'test2'
Example #5
0
def test_reload():

    config_manager.CONFIG_FILE = 'test-config.1.yaml'
    _dir = os.path.dirname(os.path.abspath(__file__))
    config = {"logging": {"level": "INFO"}}
    config_file = os.path.join(_dir, config_manager.CONFIG_FILE)

    # write 1
    write_config(config_file, config)

    config1 = config_manager.load(_dir)

    assert config["logging"]["level"] == config1["logging"]["level"]

    watcher = Watch()

    config_manager.register_handler(watcher.on_change)

    config2 = {"logging": {"level": "WARN"}}

    # write 2
    config_manager.save(config2)

    # wait for polling to happen
    wait = 3
    while not watcher.changed:
        sleep(.5)
        wait -= 1
        if wait == 0:
            raise Exception("Failed to detect change")

    config3 = config_manager.get()

    assert config["logging"]["level"] == watcher.config["logging"]["level"]
    assert config["logging"]["level"] == config3["logging"]["level"]
def test_pipeline_server_config_change():

    _dir = os.path.dirname(os.path.abspath(__file__))

    source_cfg = {
        "uri": os.path.join(_dir, "./avsource/test2-cam-person1.mkv")
    }

    config_manager.set(Config({"pipelines": {"test": [{"source": "test"}]}}))

    srv = PipelineServerEv(config_manager.get_pipelines())
    srv.start()

    config_manager.get().add_callback(srv.trigger_event)
    config_manager.get_sources().set("test", source_cfg)
    # the callback will restart the process
    assert srv.triggered
Example #7
0
def save(source_id, source):
    """Save source configuration information"""
    log.info("Saving source_id=%s", source_id)
    source = validate(source_id, source)
    config = config_manager.get()

    config["sources"][source["id"]] = source
    return config["sources"][source["id"]]
Example #8
0
    def unwatch_config(self):
        """Stop watching for configuration changes"""

        if not isinstance(self.config,
                          (config_mgm.ConfigList, config_mgm.ConfigDict)):
            return

        config = config_manager.get()
        if config is not None:
            config.remove_callback(self.on_config_change)
Example #9
0
    def watch_config(self):
        """Watch for configuration changes"""

        if not isinstance(self.config,
                          (config_mgm.ConfigList, config_mgm.ConfigDict)):
            log.warning(
                "Configuration is not reactive, cannot watch for changes")
            return

        config = config_manager.get()
        if config is not None:
            config.add_callback(self.on_config_change)
Example #10
0
def get(source_id):
    """Retrieve a source by id"""
    log.info("Get source_id=%s", source_id)

    if not source_id:
        raise BadRequest("source id is empy")

    if not isinstance(source_id, str):
        raise BadRequest("source id should be a string")

    config = config_manager.get()
    if source_id not in config["sources"].keys():
        raise NotFound("source id not found")

    return config["sources"][source_id]
Example #11
0
 def handle_config():
     if request.method == 'POST':
         config_manager.save(request.get_json())
     resp = jsonify(config_manager.get())
     return resp
Example #12
0
 def get_config():
     config = config_manager.get()
     config = config if config else {}
     return jsonify(config)
Example #13
0
def remove(source_id):
    """Remove source by id"""
    log.info("Removing source_id=%s", source_id)
    get(source_id)
    del config_manager.get()["sources"][source_id]