コード例 #1
0
def test_resolve_p2m_connections__tags(api_connections, api_agents_search,
                                       with_pagination):
    connections = {
        "agent1": {
            "connect_to": {
                "tag": {
                    "type": "tag",
                    "services": ["a", "b"]
                },
            },
            "services": "nginx",
        },
        "agent2": {
            "connect_to": {
                "tag1": {
                    "type": "tag",
                    "state": "absent"
                },
            }
        },
    }
    assert resolve.resolve_p2m_connections(
        mock.Mock(spec=sdk.ApiClient), connections) == (
            [[1, 30], [1, 31], [1, 32]],
            [[2, 40], [2, 41], [2, 42]],
            [
                resolve.ConnectionServices(1, 30, ["nginx"], ["a", "b"]),
                resolve.ConnectionServices(1, 31, ["nginx"], ["a", "b"]),
                resolve.ConnectionServices(1, 32, ["nginx"], ["a", "b"]),
            ],
        )
コード例 #2
0
def test_resolve_mesh_connections(api_connections, api_agents_search,
                                  with_pagination):
    connections = {
        "agent1": {
            "services": "a"
        },
        "agent2": {
            "services": "b"
        },
        "3": {
            "type": "id",
            "services": "c"
        },
        "agent4": {
            "state": "absent"
        },
    }
    assert resolve.resolve_mesh_connections(
        mock.Mock(spec=sdk.ApiClient), connections) == (
            [[1, 2], [1, 3], [2, 3]],
            [[1, 4], [2, 4], [3, 4]],
            [
                resolve.ConnectionServices(1, 2, ["a"], ["b"]),
                resolve.ConnectionServices(1, 3, ["a"], ["c"]),
                resolve.ConnectionServices(2, 3, ["b"], ["c"]),
            ],
        )
コード例 #3
0
def test_resolve_p2m_connections(api_connections, api_agents_search,
                                 with_pagination):
    connections = {
        "agent1": {
            "connect_to": {
                "agent2": {
                    "services": "postgre"
                },
                "agent3": {},
                "agent4": {
                    "state": "absent"
                },
            },
            "services": "nginx",
        },
        "2": {
            "state": "absent",
            "type": "id",
            "connect_to": {
                "agent5": {},
                "6": {
                    "type": "id"
                },
            },
        },
    }
    assert resolve.resolve_p2m_connections(
        mock.Mock(spec=sdk.ApiClient), connections) == (
            [[1, 2], [1, 3]],
            [[1, 4], [2, 5], [2, 6]],
            [
                resolve.ConnectionServices(1, 2, ["nginx"], ["postgre"]),
                resolve.ConnectionServices(1, 3, ["nginx"], []),
            ],
        )
コード例 #4
0
def test_resolve_p2p_connections(api_connections, api_agents_search,
                                 with_pagination):
    connections = {
        "agent1": {
            "connect_to": {
                "agent2": {},
                "services": None,
            },
            "services": ["a", "b"],
        },
        "agent3": {
            "connect_to": {
                "4": {
                    "type": "id",
                    "services": "nginx"
                }
            }
        },
        "agent4": {
            "state": "absent",
            "connect_to": {
                "agent1": {}
            }
        },
        "2": {
            "type": "id",
            "connect_to": {
                "agent4": {
                    "state": "absent"
                }
            }
        },
    }
    assert resolve.resolve_p2p_connections(
        mock.Mock(spec=sdk.ApiClient), connections) == (
            [[1, 2], [3, 4]],
            [[4, 1], [2, 4]],
            [
                resolve.ConnectionServices(1, 2, ["a", "b"], []),
                resolve.ConnectionServices(3, 4, [], ["nginx"]),
            ],
        )
コード例 #5
0
def test_resolve_present_absent(config_connections):
    agents = {f"agent {i}": i for i in range(5)}
    config_connections = list(config_connections.items())
    present = [
        (config_connections[0], config_connections[0]),
        (config_connections[0], config_connections[1]),
        (config_connections[0], config_connections[2]),
        (config_connections[2], config_connections[2]),
        (config_connections[3], config_connections[4]),
    ]
    absent = [
        (config_connections[0], config_connections[2]),
        (config_connections[1], config_connections[1]),
        (config_connections[3], config_connections[3]),
    ]
    assert resolve.resolve_present_absent(agents, present, absent) == (
        [[0, 1], [3, 4]],
        [[0, 2]],
        [
            resolve.ConnectionServices(0, 1, ["a", "b"], ["b", "c"]),
            resolve.ConnectionServices(3, 4, ["f", "g"], ["h", "i"]),
        ],
    )
コード例 #6
0
def test_resolve_present_absent__str_services():
    agents = {f"agent {i}": i for i in range(5)}
    present = [
        (
            ("agent 0", {}),
            ("agent 1", {
                "services": "nginx"
            }),
        ),
    ]
    absent = []
    assert resolve.resolve_present_absent(agents, present, absent) == (
        [[0, 1]],
        [],
        [resolve.ConnectionServices(0, 1, [], ["nginx"])],
    )
コード例 #7
0
    )
    sdk.ConnectionsApi.v1_network_connections_remove.assert_called_once()
    assert sdk.ConnectionsApi.v1_network_connections_remove.call_args_list == [
        mock.call(
            mock.ANY,
            body=models.V1NetworkConnectionsRemoveRequest(
                agent_connection_group_ids=[1, 2],
            ),
        ),
    ]


@pytest.mark.parametrize(
    "config, result",
    [
        [resolve.ConnectionServices(9, 22, [], []), ((23, False), (24, False))],
        [
            resolve.ConnectionServices(9, 22, ["nats-streaming"], []),
            ((21, True), (22, True), (23, False), (24, False)),
        ],
        [resolve.ConnectionServices(9, 22, [], ["sdn-pgadmin"]), ((23, False),)],
        [
            resolve.ConnectionServices(9, 22, ["sdn-bi"], ["streaming"]),
            ((24, False), (25, True)),
        ],
        [
            resolve.ConnectionServices(9, 22, ["missing-subnet"], []),
            ((23, False), (24, False), (123, True)),
        ],
        [
            resolve.ConnectionServices(9, 22, [], ["missing-subnet"]),