Skip to content

Commit a9ed4ad

Browse files
committed
fix addressing review comments
Signed-off-by: Martina Fabikova <[email protected]>
1 parent 25cd7db commit a9ed4ad

File tree

2 files changed

+31
-76
lines changed

2 files changed

+31
-76
lines changed

testsuite/kuadrant/policy/dns.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
from typing import Optional, Literal
55

66
import backoff
7-
import dns.resolver
87
import openshift_client as oc
9-
108
from testsuite.gateway import Referencable
119
from testsuite.kubernetes import KubernetesObject
1210
from testsuite.kubernetes.client import KubernetesClient
@@ -116,36 +114,6 @@ def wait_for_ready(self):
116114
)
117115
assert success, f"DNSRecord {self.name()} did not get ready in time"
118116

119-
def wait_for_endpoints_merged(self, expected_ips: set[str]):
120-
"""Waits until the specified IPs are present in the DNSRecord endpoints list"""
121-
122-
def _check_endpoints(obj):
123-
current_endpoints = obj.model.spec.endpoints or []
124-
found_ips = {target for ep in current_endpoints for target in ep.targets}
125-
return expected_ips.issubset(found_ips)
126-
127-
success = self.wait_until(_check_endpoints)
128-
if not success:
129-
raise AssertionError(
130-
f"Endpoints merge failed for {self.name()}. "
131-
f"Expected subset: {expected_ips}. Current: {self.model.spec.endpoints}"
132-
)
133-
134-
def wait_until_resolves(self, hostname: str, expected_ip: str):
135-
"""Waits until the hostname resolves to the expected IP using external DNS"""
136-
137-
def _check_dns(_):
138-
try:
139-
resolver = dns.resolver.Resolver()
140-
answers = resolver.resolve(hostname, "A")
141-
found_ips = {ip.to_text() for ip in answers}
142-
return expected_ip in found_ips
143-
except Exception: # pylint: disable=broad-exception-caught
144-
return False
145-
146-
success = self.wait_until(_check_dns)
147-
assert success, f"DNS resolution failed for {hostname}. Expected: {expected_ip}"
148-
149117
def get_authoritative_dns_record(self) -> str:
150118
"""Returns the authoritative DNS record created by dns operator controller"""
151119
with self.context:

testsuite/tests/singlecluster/gateway/dnspolicy/dns_records/test_dns_endpoint_provider.py

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"""
77

88
import pytest
9+
import dns.resolver
910
from testsuite.kuadrant.policy.dns import DNSRecord, DNSRecordEndpoint
11+
from testsuite.kubernetes.secret import Secret
1012

1113
SOURCE_IP1 = "91.16.35.100"
1214
SOURCE_IP2 = "172.6.13.223"
@@ -16,50 +18,50 @@
1618

1719

1820
@pytest.fixture(scope="module")
19-
def endpoint_provider_secret():
20-
"""Returns the name of the endpoint provider secret"""
21-
return "dns-provider-credentials-endpoint"
22-
23-
24-
@pytest.fixture(scope="module")
25-
def aws_provider_secret():
26-
"""Returns the name of the AWS provider secret"""
27-
return "aws-credentials"
28-
21+
def endpoint_provider_secret(request, cluster, module_label, blame):
22+
"""Creates a fresh endpoint provider secret in the test namespace"""
23+
secret_data = {"AWS_ACCESS_KEY_ID": "DUMMYACCESSKEY", "AWS_SECRET_ACCESS_KEY": "DUMMYSECRETKEY"}
24+
25+
secret = Secret.create_instance(
26+
cluster,
27+
blame("endpoint-creds"),
28+
secret_data,
29+
secret_type="kuadrant.io/endpoint",
30+
labels={"app": module_label},
31+
)
2932

30-
@pytest.fixture(scope="module")
31-
def shared_hostname(base_domain, blame):
32-
"""Returns the shared hostname used for aggregation"""
33-
return f"{blame('app')}.{base_domain}"
33+
request.addfinalizer(secret.delete)
34+
secret.commit()
35+
return secret.name()
3436

3537

3638
@pytest.fixture(scope="module")
37-
def destination_dnsrecord(cluster, blame, shared_hostname, aws_provider_secret, module_label):
39+
def destination_dnsrecord(cluster, blame, hostname, dns_provider_secret, module_label):
3840
"""Destination Record acting as the Zone"""
39-
dummy_endpoint = DNSRecordEndpoint(dnsName=shared_hostname, recordType="A", recordTTL=300, targets=[DUMMY_IP])
41+
dummy_endpoint = DNSRecordEndpoint(dnsName=hostname.hostname, recordType="A", recordTTL=300, targets=[DUMMY_IP])
4042

4143
record = DNSRecord.create_instance(
4244
cluster=cluster,
4345
name=blame("dest-zone"),
44-
root_host=shared_hostname,
46+
root_host=hostname.hostname,
4547
endpoints=[dummy_endpoint],
4648
delegate=False,
4749
labels={"app": module_label, "kuadrant.io/zone-record": "true"},
4850
)
49-
record.model["spec"]["providerRef"] = {"name": aws_provider_secret}
51+
record.model["spec"]["providerRef"] = {"name": dns_provider_secret}
5052
return record
5153

5254

5355
@pytest.fixture(scope="module")
54-
def source_dnsrecords(cluster, blame, shared_hostname, endpoint_provider_secret, module_label):
56+
def source_dnsrecords(cluster, blame, hostname, endpoint_provider_secret, module_label):
5557
"""Source Records acting as endpoint feeders"""
56-
dns_name_1 = f"src1.{shared_hostname}"
57-
dns_name_2 = f"src2.{shared_hostname}"
58+
dns_name_1 = f"src1.{hostname.hostname}"
59+
dns_name_2 = f"src2.{hostname.hostname}"
5860

5961
source1 = DNSRecord.create_instance(
6062
cluster=cluster,
6163
name=blame("src-1"),
62-
root_host=shared_hostname,
64+
root_host=hostname.hostname,
6365
endpoints=[DNSRecordEndpoint(dnsName=dns_name_1, recordType="A", recordTTL=60, targets=[SOURCE_IP1])],
6466
delegate=False,
6567
labels={"app": module_label},
@@ -69,7 +71,7 @@ def source_dnsrecords(cluster, blame, shared_hostname, endpoint_provider_secret,
6971
source2 = DNSRecord.create_instance(
7072
cluster=cluster,
7173
name=blame("src-2"),
72-
root_host=shared_hostname,
74+
root_host=hostname.hostname,
7375
endpoints=[DNSRecordEndpoint(dnsName=dns_name_2, recordType="A", recordTTL=60, targets=[SOURCE_IP2])],
7476
delegate=False,
7577
labels={"app": module_label},
@@ -82,30 +84,15 @@ def source_dnsrecords(cluster, blame, shared_hostname, endpoint_provider_secret,
8284
@pytest.fixture(scope="module", autouse=True)
8385
def commit(request, destination_dnsrecord, source_dnsrecords):
8486
"""Commits the DNSRecords to the cluster and handles cleanup"""
85-
request.addfinalizer(destination_dnsrecord.delete)
86-
destination_dnsrecord.commit()
87-
destination_dnsrecord.wait_for_ready()
87+
all_records = [destination_dnsrecord] + source_dnsrecords
8888

89-
for record in source_dnsrecords:
89+
for record in all_records:
9090
request.addfinalizer(record.delete)
9191
record.commit()
92+
record.wait_for_ready()
9293

9394

94-
def test_endpoint_provider_configuration(destination_dnsrecord, source_dnsrecords, endpoint_provider_secret):
95-
"""Verify configuration and labels"""
96-
destination_dnsrecord.refresh()
97-
assert destination_dnsrecord.model.metadata.labels.get("kuadrant.io/zone-record") == "true"
98-
99-
for record in source_dnsrecords:
100-
record.refresh()
101-
assert record.model.spec.providerRef.name == endpoint_provider_secret
102-
assert record.model.spec.rootHost == destination_dnsrecord.model.spec.rootHost
103-
104-
105-
def test_records_accessible(destination_dnsrecord, shared_hostname):
95+
def test_records_accessible(hostname):
10696
"""Verify that endpoints are merged and accessible via DNS"""
107-
# 1. Verify Merge
108-
destination_dnsrecord.wait_for_endpoints_merged({SOURCE_IP1, SOURCE_IP2})
109-
# 2. Verify DNS Resolution
110-
destination_dnsrecord.wait_until_resolves(f"src1.{shared_hostname}", SOURCE_IP1)
111-
destination_dnsrecord.wait_until_resolves(f"src2.{shared_hostname}", SOURCE_IP2)
97+
assert SOURCE_IP1 in {r.address for r in dns.resolver.resolve(f"src1.{hostname.hostname}")}
98+
assert SOURCE_IP2 in {r.address for r in dns.resolver.resolve(f"src2.{hostname.hostname}")}

0 commit comments

Comments
 (0)