Skip to content

Commit

Permalink
Add tests for dnspolicy modification
Browse files Browse the repository at this point in the history
Signed-off-by: averevki <[email protected]>
  • Loading branch information
averevki committed Oct 8, 2024
1 parent 6f54c6c commit 2fe3eda
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
9 changes: 5 additions & 4 deletions config/settings.local.yaml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
# kind: "ClusterIssuer" # Kind of Issuer, can be "Issuer" or "ClusterIssuer"
# dns:
# dns_server:
# geo_code: "DE" # dns provider geo code of the dns server
# address: "ns1.seolizer.de" # dns nameserver hostname or ip
# geo_code: "DE" # dns provider geo code of the dns server
# address: "ns1.seolizer.de" # dns nameserver hostname or ip
# dns_server2:
# geo_code: "AU" # dns provider geo code of the second dns server
# address: "ns2.seolizer.de" # second dns nameserver hostname or ip
# geo_code: "AU" # dns provider geo code of the second dns server
# address: "ns2.seolizer.de" # second dns nameserver hostname or ip
# default_geo_server: "ns3.seolizer.de" # dns nameserver for tests with default geolocation resolution
# letsencrypt:
# issuer: # Issuer object for testing TLSPolicy
# name: "letsencrypt-staging-issuer" # Name of Issuer CR
Expand Down
1 change: 1 addition & 0 deletions testsuite/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(self, name, default, **kwargs) -> None:
& Validator("dns.dns_server2.address", must_exist=True, ne=None, cast=hostname_to_ip)
& Validator("dns.dns_server2.geo_code", must_exist=True, ne=None)
),
Validator("dns.default_geo_server", must_exist=True, ne=None, cast=hostname_to_ip),
DefaultValueValidator("keycloak.url", default=fetch_service_ip("keycloak", force_http=True, port=8080)),
DefaultValueValidator("keycloak.password", default=fetch_secret("credential-sso", "ADMIN_PASSWORD")),
DefaultValueValidator("mockserver.url", default=fetch_service_ip("mockserver", force_http=True, port=1080)),
Expand Down
14 changes: 12 additions & 2 deletions testsuite/tests/multicluster/load_balanced/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
def dns_config(testconfig, skip_or_fail):
"""Configuration for DNS tests"""
try:
testconfig.validators.validate(only="dns")
testconfig.validators.validate(only=["dns.dns_server", "dns.dns_server2"])
return testconfig["dns"]
except ValidationError as exc:
return skip_or_fail(f"DNS configuration is missing: {exc}")
return skip_or_fail(f"DNS servers configuration is missing: {exc}")


@pytest.fixture(scope="package")
Expand All @@ -28,6 +28,16 @@ def dns_server2(dns_config):
return dns_config["dns_server2"]


@pytest.fixture(scope="session")
def dns_default_geo_server(testconfig, skip_or_fail):
"""Configuration of DNS server for default GEO tests"""
try:
testconfig.validators.validate(only="dns.default_geo_server")
return testconfig["dns"]["default_geo_server"]
except ValidationError as exc:
return skip_or_fail(f"DNS default geo server configuration is missing: {exc}")


@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"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Test for modification of default geolocation in DNSPolicy"""

from time import sleep

import pytest
import dns.resolver

pytestmark = [pytest.mark.multicluster]


def test_change_default_geo(hostname, gateway, gateway2, dns_policy, dns_policy2, dns_default_geo_server):
"""Test changing dns default geolocation and verify that changes are propagated"""
resolver = dns.resolver.Resolver(configure=False)
resolver.nameservers = [dns_default_geo_server]

assert resolver.resolve(hostname.hostname)[0].address == gateway.external_ip().split(":")[0]

dns_policy.model.spec.loadBalancing.defaultGeo = False
dns_policy.apply()
dns_policy.wait_for_ready()

dns_policy2.model.spec.loadBalancing.defaultGeo = True
dns_policy2.apply()
dns_policy2.wait_for_ready()

sleep(300) # wait for DNS propagation on providers
assert resolver.resolve(hostname.hostname)[0].address == gateway2.external_ip().split(":")[0]
14 changes: 14 additions & 0 deletions testsuite/tests/multicluster/load_balanced/test_change_strategy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""Test changing load-balancing strategy in DNSPolicy"""

import pytest

pytestmark = [pytest.mark.multicluster]


def test_change_lb_strategy(dns_policy2):
"""Verify that changing load-balancing strategy is not allowed"""
dns_policy2.model.spec.pop("loadBalancing")
res = dns_policy2.apply()

assert res.status() == 1
assert "loadBalancing is immutable" in res.err()

0 comments on commit 2fe3eda

Please sign in to comment.