Skip to content

Commit

Permalink
Merge pull request #604 from averevki/fix-multicluster-tests
Browse files Browse the repository at this point in the history
Fix multicluster tests
  • Loading branch information
jsmolar authored Dec 4, 2024
2 parents 2f25b0f + 91e5831 commit 133b244
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
31 changes: 26 additions & 5 deletions testsuite/tests/multicluster/load_balanced/test_change_strategy.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
"""Test changing load-balancing strategy in DNSPolicy"""

from time import sleep

import pytest
import dns.resolver

from testsuite.kuadrant.policy.dns import has_record_condition

pytestmark = [pytest.mark.multicluster]


def test_change_lb_strategy(dns_policy2):
"""Verify that changing load-balancing strategy is not allowed"""
def test_change_lb_strategy(hostname, gateway, gateway2, dns_policy2, dns_server, dns_server2, wildcard_domain):
"""Verify that removing DNSPolicy load-balancing configuration removes GEO load-balancing endpoint from the pool"""
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]

dns_policy2.model.spec.pop("loadBalancing")
res = dns_policy2.apply()
dns_policy2.apply()
assert dns_policy2.wait_until(
has_record_condition(
"Ready",
"False",
"ProviderError",
"The DNS provider failed to ensure the record: record type conflict, cannot update endpoint "
f"'{wildcard_domain}' with record type 'A' when endpoint already exists with record type 'CNAME'",
)
)

assert res.status() == 1
assert "loadBalancing is immutable" in res.err()
sleep(300) # wait for DNS propagation on providers
assert resolver.resolve(hostname.hostname)[0].address == gateway.external_ip().split(":")[0]
9 changes: 7 additions & 2 deletions testsuite/tests/multicluster/test_simple_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@ def test_simple_strategy(client, hostname, gateway, gateway2):
gw1_ip, gw2_ip = gateway.external_ip().split(":")[0], gateway2.external_ip().split(":")[0]
assert gw1_ip != gw2_ip

gw1_ip_resolved = dns.resolver.resolve(hostname.hostname)[0].address
gw2_ip_resolved = dns.resolver.resolve(hostname.hostname)[0].address
assert gw1_ip_resolved != gw2_ip_resolved, "Simple routing strategy should return IPs in a round-robin fashion"
assert {gw1_ip_resolved, gw2_ip_resolved} == {gw1_ip, gw2_ip}

for i in range(10):
assert (
dns.resolver.resolve(hostname.hostname)[0].address == gw1_ip
dns.resolver.resolve(hostname.hostname)[0].address == gw1_ip_resolved
), f"Simple routing strategy should return IPs in a round-robin fashion (iteration {i + 1})"
assert (
dns.resolver.resolve(hostname.hostname)[0].address == gw2_ip
dns.resolver.resolve(hostname.hostname)[0].address == gw2_ip_resolved
), f"Simple routing strategy should return IPs in a round-robin fashion (iteration {i + 1})"

0 comments on commit 133b244

Please sign in to comment.