Skip to content

Commit 1d9fab1

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

File tree

2 files changed

+38
-41
lines changed

2 files changed

+38
-41
lines changed

testsuite/kuadrant/policy/dns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _check_dns(_):
140140
answers = resolver.resolve(hostname, "A")
141141
found_ips = {ip.to_text() for ip in answers}
142142
return expected_ip in found_ips
143-
except Exception: # pylint: disable=broad-exception-caught
143+
except (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, dns.resolver.Timeout):
144144
return False
145145

146146
success = self.wait_until(_check_dns)

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

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
a single Destination DNSRecord (Zone) and successfully resolved via the upstream provider.
66
"""
77

8+
import base64
89
import pytest
10+
import openshift_client as oc
911
from testsuite.kuadrant.policy.dns import DNSRecord, DNSRecordEndpoint
12+
from testsuite.kubernetes.secret import Secret
1013

1114
SOURCE_IP1 = "91.16.35.100"
1215
SOURCE_IP2 = "172.6.13.223"
@@ -16,50 +19,57 @@
1619

1720

1821
@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-
22+
def endpoint_provider_secret(request, cluster, module_label, blame):
23+
"""Creates endpoint provider secret by copying from default namespace"""
24+
default_cluster = cluster.change_project("default")
25+
with default_cluster.context:
26+
source_secret = oc.selector("secret/dns-provider-credentials-endpoint").object(cls=Secret)
27+
28+
decoded_data = {}
29+
if source_secret.model.data:
30+
for key, value in source_secret.model.data.items():
31+
decoded_data[key] = base64.b64decode(value).decode("utf-8")
32+
33+
secret = Secret.create_instance(
34+
cluster,
35+
blame("endpoint-creds"),
36+
decoded_data,
37+
secret_type=source_secret.model.type,
38+
labels={"app": module_label},
39+
)
2340

24-
@pytest.fixture(scope="module")
25-
def aws_provider_secret():
26-
"""Returns the name of the AWS provider secret"""
27-
return "aws-credentials"
41+
request.addfinalizer(secret.delete)
42+
secret.commit()
43+
return secret.name()
2844

2945

3046
@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}"
34-
35-
36-
@pytest.fixture(scope="module")
37-
def destination_dnsrecord(cluster, blame, shared_hostname, aws_provider_secret, module_label):
47+
def destination_dnsrecord(cluster, blame, hostname, dns_provider_secret, module_label):
3848
"""Destination Record acting as the Zone"""
39-
dummy_endpoint = DNSRecordEndpoint(dnsName=shared_hostname, recordType="A", recordTTL=300, targets=[DUMMY_IP])
49+
dummy_endpoint = DNSRecordEndpoint(dnsName=hostname.hostname, recordType="A", recordTTL=300, targets=[DUMMY_IP])
4050

4151
record = DNSRecord.create_instance(
4252
cluster=cluster,
4353
name=blame("dest-zone"),
44-
root_host=shared_hostname,
54+
root_host=hostname.hostname,
4555
endpoints=[dummy_endpoint],
4656
delegate=False,
4757
labels={"app": module_label, "kuadrant.io/zone-record": "true"},
4858
)
49-
record.model["spec"]["providerRef"] = {"name": aws_provider_secret}
59+
record.model["spec"]["providerRef"] = {"name": dns_provider_secret}
5060
return record
5161

5262

5363
@pytest.fixture(scope="module")
54-
def source_dnsrecords(cluster, blame, shared_hostname, endpoint_provider_secret, module_label):
64+
def source_dnsrecords(cluster, blame, hostname, endpoint_provider_secret, module_label):
5565
"""Source Records acting as endpoint feeders"""
56-
dns_name_1 = f"src1.{shared_hostname}"
57-
dns_name_2 = f"src2.{shared_hostname}"
66+
dns_name_1 = f"src1.{hostname.hostname}"
67+
dns_name_2 = f"src2.{hostname.hostname}"
5868

5969
source1 = DNSRecord.create_instance(
6070
cluster=cluster,
6171
name=blame("src-1"),
62-
root_host=shared_hostname,
72+
root_host=hostname.hostname,
6373
endpoints=[DNSRecordEndpoint(dnsName=dns_name_1, recordType="A", recordTTL=60, targets=[SOURCE_IP1])],
6474
delegate=False,
6575
labels={"app": module_label},
@@ -69,7 +79,7 @@ def source_dnsrecords(cluster, blame, shared_hostname, endpoint_provider_secret,
6979
source2 = DNSRecord.create_instance(
7080
cluster=cluster,
7181
name=blame("src-2"),
72-
root_host=shared_hostname,
82+
root_host=hostname.hostname,
7383
endpoints=[DNSRecordEndpoint(dnsName=dns_name_2, recordType="A", recordTTL=60, targets=[SOURCE_IP2])],
7484
delegate=False,
7585
labels={"app": module_label},
@@ -89,23 +99,10 @@ def commit(request, destination_dnsrecord, source_dnsrecords):
8999
for record in source_dnsrecords:
90100
request.addfinalizer(record.delete)
91101
record.commit()
102+
record.wait_for_ready()
92103

93104

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):
105+
def test_records_accessible(destination_dnsrecord, hostname):
106106
"""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)
107+
destination_dnsrecord.wait_until_resolves(f"src1.{hostname.hostname}", SOURCE_IP1)
108+
destination_dnsrecord.wait_until_resolves(f"src2.{hostname.hostname}", SOURCE_IP2)

0 commit comments

Comments
 (0)