Пример #1
0
def test_filter_staticpods(monkeypatch):
    is_excluded = mock.Mock(return_value=True)
    monkeypatch.setattr('datadog_checks.kubelet.common.is_excluded', is_excluded)

    pods = json.loads(mock_from_file('pods.json'))
    pod_list_utils = PodListUtils(pods)

    # kube-proxy-gke-haissam-default-pool-be5066f1-wnvn is static
    assert pod_list_utils.is_excluded("cid", "260c2b1d43b094af6d6b4ccba082c2db") is False
    is_excluded.assert_not_called()

    # fluentd-gcp-v2.0.10-9q9t4 is not static
    assert pod_list_utils.is_excluded("docker://5741ed2471c0e458b6b95db40ba05d1a5ee168256638a0264f08703e48d76561",
                                      "2edfd4d9-10ce-11e8-bd5a-42010af00137") is True
Пример #2
0
def test_container_filter(monkeypatch):
    c_is_excluded = mock.Mock(return_value=False)
    monkeypatch.setattr('datadog_checks.kubelet.common.c_is_excluded',
                        c_is_excluded)

    long_cid = "docker://a335589109ce5506aa69ba7481fc3e6c943abd23c5277016c92dac15d0f40479"
    ctr_name = "datadog-agent"
    ctr_image = "datadog/agent-dev:haissam-tagger-pod-entity"
    namespace = "default"

    pods = json.loads(mock_from_file('pods.json'))
    pod_list_utils = PodListUtils(pods)

    assert pod_list_utils is not None
    assert len(pod_list_utils.containers) == 10
    assert long_cid in pod_list_utils.containers
    c_is_excluded.assert_not_called()

    # Test cid == None
    c_is_excluded.reset_mock()
    assert pod_list_utils.is_excluded(None) is True
    c_is_excluded.assert_not_called()

    # Test cid == ""
    c_is_excluded.reset_mock()
    assert pod_list_utils.is_excluded("") is True
    c_is_excluded.assert_not_called()

    # Test non-existing container
    c_is_excluded.reset_mock()
    assert pod_list_utils.is_excluded("invalid") is True
    c_is_excluded.assert_not_called()

    # Test existing unfiltered container
    c_is_excluded.reset_mock()
    assert pod_list_utils.is_excluded(long_cid) is False
    c_is_excluded.assert_called_once()
    c_is_excluded.assert_called_with(ctr_name, ctr_image, namespace)

    # Clear exclusion cache
    pod_list_utils.cache = {}

    # Test existing filtered container
    c_is_excluded.reset_mock()
    c_is_excluded.return_value = True
    assert pod_list_utils.is_excluded(long_cid) is True
    c_is_excluded.assert_called_once()
    c_is_excluded.assert_called_with(ctr_name, ctr_image, namespace)