From b6dc9626146780baea30009ca80b56c5a553b505 Mon Sep 17 00:00:00 2001 From: rasswanth-s <43314053+rasswanth-s@users.noreply.github.com> Date: Sun, 15 Oct 2023 17:43:16 +0530 Subject: [PATCH] added new gateway connection tests for kubernetes fixed stack integration tests --- tests/integration/conftest.py | 16 +++++++ tests/integration/network/client_test.py | 2 +- tests/integration/network/gateway_test.py | 52 +++++++++++++++++++++++ tox.ini | 32 +++++++------- 4 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 tests/integration/network/gateway_test.py diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index b382ba40876..27e733e75a1 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,7 +1,23 @@ # third party import _pytest +import pytest def pytest_configure(config: _pytest.config.Config) -> None: config.addinivalue_line("markers", "frontend: frontend integration tests") config.addinivalue_line("markers", "network: network integration tests") + + +@pytest.fixture +def gateway_port() -> int: + return 9081 + + +@pytest.fixture +def domain_1_port() -> int: + return 9082 + + +@pytest.fixture +def domain_2_port() -> int: + return 9083 diff --git a/tests/integration/network/client_test.py b/tests/integration/network/client_test.py index 5eed2c1dabd..92c03510f6e 100644 --- a/tests/integration/network/client_test.py +++ b/tests/integration/network/client_test.py @@ -22,7 +22,7 @@ def test_client_type(node_metadata): @pytest.mark.parametrize( - "node_metadata", [(NETWORK_PORT, "test_gateway_1"), (DOMAIN_PORT, "test_domain_1")] + "node_metadata", [(NETWORK_PORT, "test-gateway-1"), (DOMAIN_PORT, "test-domain-1")] ) @pytest.mark.network def test_client_name(node_metadata): diff --git a/tests/integration/network/gateway_test.py b/tests/integration/network/gateway_test.py new file mode 100644 index 00000000000..3f5034586ad --- /dev/null +++ b/tests/integration/network/gateway_test.py @@ -0,0 +1,52 @@ +# syft absolute +import syft as sy +from syft.abstract_node import NodeType +from syft.client.domain_client import DomainClient +from syft.client.gateway_client import GatewayClient +from syft.service.network.node_peer import NodePeer +from syft.service.response import SyftSuccess +from syft.service.user.user_roles import ServiceRole + + +def test_domain_connect_to_gateway(domain_1_port, gateway_port): + gateway_client: GatewayClient = sy.login( + port=gateway_port, email="info@openmined.org", password="changethis" + ) + + domain_client: DomainClient = sy.login( + port=domain_1_port, email="info@openmined.org", password="changethis" + ) + + result = domain_client.connect_to_gateway(gateway_client) + assert isinstance(result, SyftSuccess) + + assert len(domain_client.peers) == 1 + assert len(gateway_client.peers) == 1 + + proxy_domain_client = gateway_client.peers[0] + domain_peer = domain_client.peers[0] + + assert isinstance(proxy_domain_client, DomainClient) + assert isinstance(domain_peer, NodePeer) + + # Domain's peer is a gateway and vice-versa + assert domain_peer.node_type == NodeType.GATEWAY + + assert gateway_client.name == domain_peer.name + assert domain_client.name == proxy_domain_client.name + + assert len(gateway_client.domains) == 1 + assert len(gateway_client.enclaves) == 0 + + assert proxy_domain_client.metadata == domain_client.metadata + assert proxy_domain_client.user_role == ServiceRole.NONE + + domain_client.login(email="info@openmined.org", password="changethis") + proxy_domain_client.login(email="info@openmined.org", password="changethis") + + assert proxy_domain_client.logged_in_user == "info@openmined.org" + assert proxy_domain_client.user_role == ServiceRole.ADMIN + assert proxy_domain_client.credentials == domain_client.credentials + assert ( + proxy_domain_client.api.endpoints.keys() == domain_client.api.endpoints.keys() + ) diff --git a/tox.ini b/tox.ini index 2024feab95d..6a0739557ad 100644 --- a/tox.ini +++ b/tox.ini @@ -260,31 +260,30 @@ commands = bash -c "docker volume rm test-domain-1_mongo-data --force || true" bash -c "docker volume rm test-domain-1_credentials-data --force || true" bash -c "docker volume rm test-domain-1_seaweedfs-data --force || true" - bash -c "docker volume rm test-domain-2_mongo-data --force || true" - bash -c "docker volume rm test-domain-2_credentials-data --force || true" - bash -c "docker volume rm test-domain-2_seaweedfs-data --force || true" + bash -c "docker volume rm test-domain-1_tailscale-data --force || true" + ; bash -c "docker volume rm test-domain-2_mongo-data --force || true" + ; bash -c "docker volume rm test-domain-2_credentials-data --force || true" + ; bash -c "docker volume rm test-domain-2_seaweedfs-data --force || true" + ; bash -c "docker volume rm test-domain-2_tailscale-data --force || true" bash -c "docker volume rm test-gateway-1_mongo-data --force || true" bash -c "docker volume rm test-gateway-1_credentials-data --force || true" bash -c "docker volume rm test-gateway-1_seaweedfs-data --force || true" - - bash -c "docker volume rm test-domain-1_tailscale-data --force || true" - bash -c "docker volume rm test-domain-2_tailscale-data --force || true" bash -c "docker volume rm test-gateway-1_tailscale-data --force || true" bash -c "docker volume rm test-gateway-1_headscale-data --force || true" python -c 'import syft as sy; sy.stage_protocol_changes()' - bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test_gateway_1 network to docker:9081 $HAGRID_FLAGS --no-health-checks --verbose --no-warnings --dev' - bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test_domain_1 domain to docker:9082 $HAGRID_FLAGS --no-health-checks --enable-signup --verbose --no-warnings --dev' - bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test_domain_2 domain to docker:9083 --headless $HAGRID_FLAGS --enable-signup --no-health-checks --verbose --no-warnings --dev' + bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test-gateway-1 network to docker:9081 $HAGRID_FLAGS --no-health-checks --verbose --no-warnings --dev' + bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test-domain-1 domain to docker:9082 $HAGRID_FLAGS --no-health-checks --enable-signup --verbose --no-warnings --dev' + ; bash -c 'HAGRID_ART=$HAGRID_ART hagrid launch test-domain-2 domain to docker:9083 --headless $HAGRID_FLAGS --enable-signup --no-health-checks --verbose --no-warnings --dev' ; wait for nodes to start docker ps bash -c "echo Waiting for Nodes; date" - bash -c '(docker logs test_domain_1-frontend-1 -f &) | grep -q -E "Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/" || true' - bash -c '(docker logs test_domain_1-backend-1 -f &) | grep -q "Application startup complete" || true' - bash -c '(docker logs test_domain_2-backend-1 -f &) | grep -q "Application startup complete" || true' - bash -c '(docker logs test_gateway_1-backend-1 -f &) | grep -q "Application startup complete" || true' + bash -c '(docker logs test-domain-1-frontend-1 -f &) | grep -q -E "Network:\s+https?://[a-zA-Z0-9.-]+:[0-9]+/" || true' + bash -c '(docker logs test-domain-1-backend-1 -f &) | grep -q "Application startup complete" || true' + ; bash -c '(docker logs test_domain_2-backend-1 -f &) | grep -q "Application startup complete" || true' + bash -c '(docker logs test-gateway-1-backend-1 -f &) | grep -q "Application startup complete" || true' ; frontend bash -c 'if [[ "$PYTEST_MODULES" == *"frontend"* ]]; then \ @@ -651,7 +650,7 @@ commands = cd packages/grid && \ (r=5;while ! \ devspace --no-warn --kube-context "k3d-$NODE_NAME" --namespace $NODE_NAME \ - --var DOMAIN_NAME=$NODE_NAME \ + --var NODE_NAME=$NODE_NAME \ --var NETWORK_CHECK_INTERVAL=5 \ --var ASSOCIATION_TIMEOUT=100 \ --var TEST_MODE=1 \ @@ -669,7 +668,7 @@ commands = cd packages/grid && \ (r=5;while ! \ devspace --no-warn --kube-context "k3d-$NODE_NAME" --namespace $NODE_NAME \ - --var DOMAIN_NAME=$NODE_NAME \ + --var NODE_NAME=$NODE_NAME \ --var DOMAIN_CHECK_INTERVAL=5 \ --var ASSOCIATION_TIMEOUT=100 \ --var TEST_MODE=1 \ @@ -753,6 +752,9 @@ commands = # Run 0.8 notebooks pytest --nbmake notebooks/api/0.8 -p no:randomly -vvvv -k 'not 06' + #Integration + Gateway Connection Tests + pytest tests/integration/network -p no:randomly -vvvv + # deleting clusters created bash -c "k3d cluster delete test-gateway-1 || true" bash -c "k3d cluster delete test-domain-1 || true"