-
Notifications
You must be signed in to change notification settings - Fork 23
test(dns): Verify DNS Endpoint Provider aggregation logic #830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| """ | ||
| Tests the DNS Endpoint Provider aggregation logic. | ||
|
|
||
| Verifies that endpoints from multiple Source DNSRecords are correctly merged into | ||
| a single Destination DNSRecord (Zone) and successfully resolved via the upstream provider. | ||
| """ | ||
|
|
||
| import pytest | ||
| import dns.resolver | ||
| from testsuite.kuadrant.policy.dns import DNSRecord, DNSRecordEndpoint | ||
| from testsuite.kubernetes.secret import Secret | ||
|
|
||
| SOURCE_IP1 = "91.16.35.100" | ||
| SOURCE_IP2 = "172.6.13.223" | ||
| DUMMY_IP = "127.0.0.1" | ||
|
|
||
| pytestmark = [pytest.mark.dnspolicy] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def endpoint_provider_secret(request, cluster, module_label, blame): | ||
| """Creates a fresh endpoint provider secret in the test namespace""" | ||
| secret_data = {"AWS_ACCESS_KEY_ID": "DUMMYACCESSKEY", "AWS_SECRET_ACCESS_KEY": "DUMMYSECRETKEY"} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What you need these secret values for? afaik only |
||
|
|
||
| secret = Secret.create_instance( | ||
| cluster, | ||
| blame("endpoint-creds"), | ||
| secret_data, | ||
| secret_type="kuadrant.io/endpoint", | ||
| labels={"app": module_label}, | ||
| ) | ||
|
|
||
| request.addfinalizer(secret.delete) | ||
| secret.commit() | ||
| return secret.name() | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def destination_dnsrecord(cluster, blame, hostname, dns_provider_secret, module_label): | ||
| """Destination Record acting as the Zone""" | ||
| dummy_endpoint = DNSRecordEndpoint(dnsName=hostname.hostname, recordType="A", recordTTL=300, targets=[DUMMY_IP]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see you use this endpoint for anything inside the test. You should be able to configure dns record without any endpoints, with rootHost and providerRef filled only. |
||
|
|
||
| record = DNSRecord.create_instance( | ||
| cluster=cluster, | ||
| name=blame("dest-zone"), | ||
| root_host=hostname.hostname, | ||
| endpoints=[dummy_endpoint], | ||
| delegate=False, | ||
| labels={"app": module_label, "kuadrant.io/zone-record": "true"}, | ||
| ) | ||
| record.model["spec"]["providerRef"] = {"name": dns_provider_secret} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add provider ref as a parameter to dns record class. Try to add reusable testsuite actions into methods, which might be also useful for the future tests |
||
| return record | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module") | ||
| def source_dnsrecords(cluster, blame, hostname, endpoint_provider_secret, module_label): | ||
| """Source Records acting as endpoint feeders""" | ||
| dns_name_1 = f"src1.{hostname.hostname}" | ||
| dns_name_2 = f"src2.{hostname.hostname}" | ||
|
|
||
| source1 = DNSRecord.create_instance( | ||
| cluster=cluster, | ||
| name=blame("src-1"), | ||
| root_host=hostname.hostname, | ||
| endpoints=[DNSRecordEndpoint(dnsName=dns_name_1, recordType="A", recordTTL=60, targets=[SOURCE_IP1])], | ||
| delegate=False, | ||
| labels={"app": module_label}, | ||
| ) | ||
| source1.model["spec"]["providerRef"] = {"name": endpoint_provider_secret} | ||
|
|
||
| source2 = DNSRecord.create_instance( | ||
| cluster=cluster, | ||
| name=blame("src-2"), | ||
| root_host=hostname.hostname, | ||
| endpoints=[DNSRecordEndpoint(dnsName=dns_name_2, recordType="A", recordTTL=60, targets=[SOURCE_IP2])], | ||
| delegate=False, | ||
| labels={"app": module_label}, | ||
| ) | ||
| source2.model["spec"]["providerRef"] = {"name": endpoint_provider_secret} | ||
|
|
||
| return [source1, source2] | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def commit(request, destination_dnsrecord, source_dnsrecords): | ||
| """Commits the DNSRecords to the cluster and handles cleanup""" | ||
| all_records = [destination_dnsrecord] + source_dnsrecords | ||
|
|
||
| for record in all_records: | ||
| request.addfinalizer(record.delete) | ||
| record.commit() | ||
| record.wait_for_ready() | ||
|
|
||
|
|
||
| def test_records_accessible(hostname): | ||
| """Verify that endpoints are merged and accessible via DNS""" | ||
| assert SOURCE_IP1 in {r.address for r in dns.resolver.resolve(f"src1.{hostname.hostname}")} | ||
| assert SOURCE_IP2 in {r.address for r in dns.resolver.resolve(f"src2.{hostname.hostname}")} | ||
|
Comment on lines
+97
to
+98
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also assert if there is only a single IP returned from each hostname |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python imports usually separated into 3 groups: preinstalled python packages, external packages (the ones we add through the poetry), and internal testsuite packages. They are separated with empty lines to make it easier to manage and traverse imports