Ejemplo n.º 1
0
def test_scheduler_init():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )
Ejemplo n.º 2
0
def test_ok_config():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')
    metrics = [
        model.Metric(
            id='cpu',
            endpoint='/cpu',
            frequency=model.TimeDetail(
                value=1,
                unit=model.TimeUnit('m'),
            ),
            expectedTime=model.TimeDetail(
                value=50,
                unit=model.TimeUnit('ms'),
            ),
            timeout=model.TimeDetail(
                value=200,
                unit=model.TimeUnit('ms'),
            ),
            deleteAfter=model.TimeDetail(
                value=7,
                unit=model.TimeUnit('d'),
            ),
            authToken='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            baseUrl='http://127.0.0.1:1338',
        )
    ]
    components = [
        model.Component(
            id='test-component',
            name='test',
            systemId='openmonitor',
            baseUrl='http://127.0.0.1:1338',
            ref='https://github.com/openmonitor/test',
            authToken='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            metrics=metrics,
        )
    ]
    systems = [
        model.System(
            id='openmonitor',
            name='OpenMonitor',
            ref='https://github.com/openmonitor',
        )
    ]
    cfg_expected = model.Config(
        components=components,
        systems=systems,
        version=model.Version('v2'),
        cacheCallback='http://monitor-api:8012',
    )
    assert cfg == cfg_expected
Ejemplo n.º 3
0
def test_scheduler_observer():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    scheduler = sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )

    scheduler.schedule_events()

    # make and register observer
    obs = observer.Observer(
        name='schedule-observer',
        callback='http://127.0.0.1:1337',
    )
    scheduler.register_observer(observer=obs)
Ejemplo n.º 4
0
def test_scheduler_metrics():
    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    scheduler = sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )

    resp = requests.get(url='https://zeekay.dev/404', )

    with pytest.raises(json.decoder.JSONDecodeError):
        scheduler._parse_result(
            resp=resp,
            timeout=False,
            metric_id='bar',
            component_id='bar',
        )
Ejemplo n.º 5
0
def test_scheduler_observer_call():
    def _fake_callable():
        pass

    cfg_fac = fac.ConfigFactory()
    cfg = cfg_fac.make_config(config_path='./test/config_1.yaml')

    conn_fac = db_fac.DatabaseConnectionFactory()
    conn = conn_fac.make_connection()

    scheduler = sched.Scheduler(
        cfg=cfg,
        conn=conn,
    )

    obs = observer.Observer(
        name='schedule-observer-test',
        callback='404',
    )

    scheduler.register_observer(observer=obs)
    for obs in scheduler.observer:
        obs.call_by_callable(callable=_fake_callable)
Ejemplo n.º 6
0
def test_faulty_component_config():
    cfg_fac = fac.ConfigFactory()
    with pytest.raises(AttributeError):
        cfg_fac.make_config(config_path='./test/config_3.yaml')
Ejemplo n.º 7
0
def test_no_cfg():
    cfg_fac = fac.ConfigFactory()
    with pytest.raises(FileNotFoundError):
        cfg_fac.make_config(config_path='./test/config_missing.yaml')
Ejemplo n.º 8
0
def test_faulty_system_config():
    cfg_fac = fac.ConfigFactory()
    with pytest.raises(exceptions.OpenmonitorConfigError):
        cfg_fac.make_config(config_path='./test/config_2.yaml')