示例#1
0
    def wrapper(responses):
        mock_client = get_mock_client(responses)

        monkeypatch.setattr(
            "kube_resource_report.cluster_discovery.ClusterRegistryDiscoverer.get_clusters",
            lambda x: [
                Cluster("test-cluster-1", "test-cluster-1",
                        "https://test-cluster-1.example.org", mock_client)
            ],
        )

        cluster_summaries = generate_report(
            [],
            "https://cluster-registry",
            None,
            set(),
            None,
            False,
            False,
            str(output_dir),
            set(["kube-system"]),
            None,
            None,
            100.0,  # additional_cost_per_cluster
            1.0,  # alpha ema
            {},
            None,
            None,
            ["worker", "node"])
        assert len(cluster_summaries) == 1
        return cluster_summaries
示例#2
0
def test_generate_report(tmpdir, monkeypatch):
    output_dir = tmpdir.mkdir("output")
    monkeypatch.setattr("kube_resource_report.cluster_discovery.tokens.get",
                        lambda x: "mytok")
    monkeypatch.setattr(
        "kube_resource_report.cluster_discovery.ClusterRegistryDiscoverer.get_clusters",
        lambda x:
        [Cluster("test-cluster-1", "https://test-cluster-1.example.org")],
    )

    responses = {
        "/api/v1/nodes": {
            "items": [{
                "metadata": {
                    "name": "node-1",
                    "labels": {}
                },
                "status": {
                    "capacity": {
                        "cpu": "1",
                        "memory": "1Gi"
                    },
                    "allocatable": {
                        "cpu": "1",
                        "memory": "1Gi"
                    },
                },
            }]
        },
        "/api/v1/pods": {
            "items": []
        },
        "/apis/extensions/v1beta1/ingresses": {
            "items": []
        },
    }

    monkeypatch.setattr(
        "kube_resource_report.report.request",
        lambda cluster, path: MagicMock(json=lambda: responses.get(path)),
    )
    cluster_summaries = generate_report(
        [],
        "https://cluster-registry",
        None,
        set(),
        None,
        False,
        False,
        str(output_dir),
        set(["kube-system"]),
        None,
        None,
        0,
        None,
    )
    assert len(cluster_summaries) == 1
示例#3
0
 def wrapper(responses):
     monkeypatch.setattr(
         "kube_resource_report.report.request",
         lambda cluster, path: MagicMock(json=lambda: responses.get(path)),
     )
     cluster_summaries = generate_report([], "https://cluster-registry",
                                         None, set(), None, False, False,
                                         str(output_dir),
                                         set(["kube-system"]), None, None,
                                         100.0, None, "worker")
     assert len(cluster_summaries) == 1
     return cluster_summaries