def test_config_strict_mode_errors():
    config.register(Item, strict_mode=True)

    test_config_path = testing.relative_module_path(__file__, 'test_config.yaml')

    with pytest.raises(ConfigLoadError, match='missing type declaration'):
        config.load_config(test_config_path)
Beispiel #2
0
def register_components(extra_components: List[str]):
    for component in REGISTERED_COMPONENTS:
        config.register(component)

    for component in extra_components:
        # Load external class ignored its requirements.
        ep = pkg_resources.EntryPoint.parse('external_cls=%s' % component)
        cls = ep.resolve()
        config.register(cls)
Beispiel #3
0
def test_tester(mock_sys_exit: MagicMock, mock_create_cgroup: MagicMock,
                mock_delete_cgroup: MagicMock):
    register(FileCheck)
    register(MetricCheck)
    register(StaticAllocator)

    mock_check = MagicMock()

    tester = IntegrationTester('tests/tester/test_config.yaml')

    tester.testcases[0]['checks'] = [mock_check]
    tester.testcases[1]['checks'] = [mock_check]

    # Prepare first testcase.
    assert tester.get_tasks() == [
        Task(name='task1',
             task_id='task1',
             cgroup_path='/test/task1',
             labels={},
             resources={},
             subcgroups_paths=[]),
        Task(name='task2',
             task_id='task2',
             cgroup_path='/test/task2',
             labels={},
             resources={},
             subcgroups_paths=[])
    ]

    assert mock_create_cgroup.call_count == 2

    # Do checks from first testcase. Prepare second one.
    assert tester.get_tasks() == [
        Task(name='task2',
             task_id='task2',
             cgroup_path='/test/task2',
             labels={},
             resources={},
             subcgroups_paths=[]),
        Task(name='task4',
             task_id='task4',
             cgroup_path='/test/task4',
             labels={},
             resources={},
             subcgroups_paths=[])
    ]

    assert mock_check.check.call_count == 1
    assert mock_create_cgroup.call_count == 3
    assert mock_delete_cgroup.call_count == 1

    tester.get_tasks()

    assert mock_check.check.call_count == 2
    assert mock_create_cgroup.call_count == 3
    assert mock_delete_cgroup.call_count == 3

    mock_sys_exit.assert_called()
def test_config_with_simple_classes():
    # Another method for registering items (other than using decorator).
    config.register(Item, strict_mode=False)

    test_config_path = testing.relative_module_path(__file__, 'test_config.yaml')

    data = config.load_config(test_config_path)

    foo_with_defaults = data['foo_with_defaults']
    assert foo_with_defaults.f == 1

    empty_boo = data['empty_boo']
    assert empty_boo.foo is None

    foo = data['foo']
    boo = data['boo']

    assert foo.s == 'some_string'
    assert foo.f == 2.5

    assert boo.foo is foo
    assert len(boo.items) == 2
    assert isinstance(boo.items[0], Item)
Beispiel #5
0
def register_components():
    register(Prometheus)
    register(AppDataProvider)
    register(Queries)
Beispiel #6
0
def register_dataproviders():
    register(Kubeapi)
    register(Prometheus)
    register(Queries)
    register(ClusterDataProvider)
    register(ClusterScoreDataProvider)
Beispiel #7
0
def register_algorithms():
    register(Fit)
    register(LeastUsedBAR)
    register(LeastUsed)
    register(BAR)
    register(HierBAR)
    register(StaticAssigner)
    register(Score)
    register(DramHitRatioProvision)
Beispiel #8
0
def register_components(extra_components: List[str]):
    config.register(detection.DetectionRunner)
    config.register(allocation.AllocationRunner)
    config.register(measurement.MeasurementRunner)
    config.register(mesos.MesosNode)
    config.register(kubernetes.KubernetesNode)
    config.register(storage.LogStorage)
    config.register(storage.KafkaStorage)
    config.register(detectors.NOPAnomalyDetector)
    config.register(allocators.NOPAllocator)
    config.register(allocators.AllocationConfiguration)
    config.register(kubernetes.CgroupDriverType)
    config.register(static_node.StaticNode)
    config.register(static_allocator.StaticAllocator)
    config.register(security.SSL)

    for component in extra_components:
        # Load external class ignored its requirements.
        ep = pkg_resources.EntryPoint.parse('external_cls=%s' % component)
        cls = ep.resolve()
        config.register(cls)