|
3 | 3 | from dataclasses import dataclass
|
4 | 4 | from typing import Optional, Literal
|
5 | 5 |
|
| 6 | +import openshift_client as oc |
| 7 | + |
6 | 8 | from testsuite.gateway import Referencable
|
7 | 9 | from testsuite.kubernetes import KubernetesObject
|
8 | 10 | from testsuite.kubernetes.client import KubernetesClient
|
@@ -54,8 +56,13 @@ class HealthCheck: # pylint: disable=invalid-name
|
54 | 56 | class DNSHealthCheckProbe(KubernetesObject):
|
55 | 57 | """DNSHealthCheckProbe object"""
|
56 | 58 |
|
| 59 | + def _status_ready(self): |
| 60 | + """Returns True if DNSHealthCheckProbe status.healthy field has appeared""" |
| 61 | + return self.wait_until(lambda obj: obj.model.status.healthy is not oc.Missing) |
| 62 | + |
57 | 63 | def is_healthy(self) -> bool:
|
58 | 64 | """Returns True if DNSHealthCheckProbe endpoint is healthy"""
|
| 65 | + assert self._status_ready(), "DNSHealthCheckProbe status wasn't ready in time" |
59 | 66 | return self.refresh().model.status.healthy
|
60 | 67 |
|
61 | 68 |
|
@@ -93,10 +100,23 @@ def set_health_check(self, health_check: HealthCheck):
|
93 | 100 | """Sets health check for DNSPolicy"""
|
94 | 101 | self.model["spec"]["healthCheck"] = asdict(health_check)
|
95 | 102 |
|
| 103 | + def _get_dns_record(self): |
| 104 | + """Returns DNSRecord object for the created DNSPolicy""" |
| 105 | + with self.context: |
| 106 | + assert self.wait_until( |
| 107 | + lambda obj: len(obj.get_owned("dnsrecords.kuadrant.io")) > 0 |
| 108 | + ), "The corresponding DNSRecord object wasn't created in time" |
| 109 | + dns_record = self.get_owned("dnsrecords.kuadrant.io")[0] |
| 110 | + return KubernetesObject(dns_record.model, context=self.context) |
| 111 | + |
96 | 112 | def get_dns_health_probe(self) -> DNSHealthCheckProbe:
|
97 | 113 | """Returns DNSHealthCheckProbe object for the created DNSPolicy"""
|
| 114 | + dns_record = self._get_dns_record() |
98 | 115 | with self.context:
|
99 |
| - dns_probe = self.get_owned("dnsrecords.kuadrant.io")[0].get_owned("DNSHealthCheckProbe")[0] |
| 116 | + assert dns_record.wait_until( |
| 117 | + lambda obj: len(obj.get_owned("DNSHealthCheckProbe")) > 0 |
| 118 | + ), "The corresponding DNSHealthCheckProbe object wasn't created in time" |
| 119 | + dns_probe = dns_record.get_owned("DNSHealthCheckProbe")[0] |
100 | 120 | return DNSHealthCheckProbe(dns_probe.model, context=self.context)
|
101 | 121 |
|
102 | 122 | def wait_for_full_enforced(self, timelimit=300):
|
|
0 commit comments