-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: averevki <[email protected]>
- Loading branch information
Showing
8 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Conftest for load-balanced multicluster tests""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.dns import DNSPolicy, LoadBalancing | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def dns_config(testconfig): | ||
"""Configuration for DNS tests""" | ||
testconfig.validators.validate(only="dns") | ||
return testconfig["dns"] | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def dns_server(dns_config): | ||
"""DNS server in the first geo region""" | ||
return dns_config["dns_server"] | ||
|
||
|
||
@pytest.fixture(scope="package") | ||
def dns_server2(dns_config): | ||
"""DNS server in the second geo region""" | ||
return dns_config["dns_server2"] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def dns_policy(blame, cluster, gateway, dns_server, module_label, dns_provider_secret): | ||
"""DNSPolicy with load-balancing for the first cluster""" | ||
load_balancing = LoadBalancing(default_geo=dns_server["geo_code"], default_weight=10) | ||
return DNSPolicy.create_instance( | ||
cluster, blame("dns"), gateway, dns_provider_secret, load_balancing, labels={"app": module_label} | ||
) | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def dns_policy2(blame, cluster2, gateway2, dns_server, module_label, dns_provider_secret): | ||
"""DNSPolicy with load-balancing for the second cluster""" | ||
load_balancing = LoadBalancing(default_geo=dns_server["geo_code"], default_weight=10) | ||
return DNSPolicy.create_instance( | ||
cluster2, blame("dns"), gateway2, dns_provider_secret, load_balancing, labels={"app": module_label} | ||
) |
32 changes: 32 additions & 0 deletions
32
testsuite/tests/multicluster/load_balanced/test_load_balanced_geo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""Test load-balancing based on geolocation""" | ||
|
||
import pytest | ||
import dns.name | ||
import dns.resolver | ||
|
||
pytestmark = [pytest.mark.multicluster] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def gateway2(gateway2, dns_server2): | ||
"""Overwrite second gateway to have a different geocode""" | ||
gateway2.label({"kuadrant.io/lb-attribute-geo-code": dns_server2["geo_code"]}) | ||
return gateway2 | ||
|
||
|
||
def test_load_balanced_geo(client, hostname, gateway, gateway2, dns_server, dns_server2): | ||
""" | ||
- Verify that request to the hostname is successful | ||
- Verify that DNS resolution through nameservers from different regions returns according IPs | ||
""" | ||
result = client.get("/get") | ||
assert not result.has_dns_error(), result.error | ||
assert not result.has_cert_verify_error(), result.error | ||
assert result.status_code == 200 | ||
|
||
resolver = dns.resolver.Resolver(configure=False) | ||
resolver.nameservers = [dns_server["address"]] | ||
assert resolver.resolve(hostname.hostname)[0].address == gateway.external_ip().split(":")[0] | ||
|
||
resolver.nameservers = [dns_server2["address"]] | ||
assert resolver.resolve(hostname.hostname)[0].address == gateway2.external_ip().split(":")[0] |
15 changes: 15 additions & 0 deletions
15
testsuite/tests/multicluster/load_balanced/test_unsupported_geocode.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Test not supported geocode in geo load-balancing""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy import has_condition | ||
|
||
pytestmark = [pytest.mark.multicluster] | ||
|
||
|
||
def test_unsupported_geocode(dns_policy): | ||
"""Change default geocode to not existent one and verify that policy became not enforced""" | ||
dns_policy.model.spec.loadBalancing.geo.defaultGeo = "XX" | ||
dns_policy.apply() | ||
|
||
assert dns_policy.wait_until(has_condition("Enforced", "False")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters