@@ -106,7 +106,8 @@ def _transfer_keyring():
106106 )
107107
108108
109- def _send_update (update : dns .update .Update ):
109+ def _send_update (update : dns .update .Update ) -> None :
110+ """Send a single DNS update to Knot and hard-fail on any error."""
110111 try :
111112 host = _knot_host_ip ()
112113 response = dns .query .tcp (
@@ -130,40 +131,6 @@ def _send_update(update: dns.update.Update):
130131 )
131132
132133
133- def _send_update_with_retry (
134- update : dns .update .Update ,
135- * ,
136- attempts : int = 5 ,
137- delay_seconds : float = 1.0 ,
138- retry_rcodes : tuple [str , ...] = ("NOTAUTH" , "SERVFAIL" ),
139- ):
140- last_exc = None
141- for attempt in range (attempts ):
142- try :
143- _send_update (update )
144- return
145- except KnotException as exc :
146- last_exc = exc
147- zone = update .zone
148- zone_text = zone .to_text () if hasattr (zone , "to_text" ) else str (zone )
149- logger .info (
150- "Knot update retry %d/%d for zone=%s error=%s" ,
151- attempt + 1 ,
152- attempts ,
153- zone_text ,
154- exc ,
155- )
156- if attempt < attempts - 1 and (
157- any (code in str (exc ) for code in retry_rcodes )
158- or "timed out" in str (exc )
159- ):
160- _sleep (delay_seconds )
161- continue
162- raise
163- if last_exc is not None :
164- raise last_exc
165-
166-
167134def _catalog_member_subname (zone ):
168135 zone = zone .rstrip ("." ) + "."
169136 return f"{ sha1 (zone .encode ()).hexdigest ()} .zones"
@@ -184,10 +151,11 @@ def _new_update(zone):
184151
185152
186153def create_zone (name ):
154+ """Create a zone via the catalog update and verify it becomes available."""
187155 catalog_update = _new_update (settings .CATALOG_ZONE )
188156 catalog_update .replace (_catalog_record_name (name ), 0 , "PTR" , name .rstrip ("." ) + "." )
189157 try :
190- _send_update_with_retry (catalog_update )
158+ _send_update (catalog_update )
191159 except KnotException as exc :
192160 if "timed out" not in str (exc ):
193161 raise
@@ -197,13 +165,14 @@ def create_zone(name):
197165
198166
199167def ensure_default_ns (name ):
168+ """Ensure default NS/SOA records exist for a zone and are visible."""
200169 if not wait_for_zone (name , attempts = 60 , interval_seconds = 0.5 ):
201170 raise KnotException (f"Knot zone { name } not ready for updates" )
202171 update = _new_update (name )
203172 apex = name .rstrip ("." ) + "."
204173 update .replace (apex , settings .DEFAULT_NS_TTL , "NS" , * settings .DEFAULT_NS )
205174 update .replace (apex , settings .DEFAULT_NS_TTL , "SOA" , DEFAULT_SOA_CONTENT )
206- _send_update_with_retry (update , attempts = 10 , delay_seconds = 1.0 )
175+ _send_update (update )
207176 if not wait_for_zone (name , attempts = 60 , interval_seconds = 0.5 ):
208177 raise KnotException (f"Knot zone { name } not ready for updates" )
209178
@@ -341,7 +310,7 @@ def import_csk_key(name, *, dnskey, private_key=None):
341310 except Exception :
342311 pass
343312 if has_changes :
344- _send_update_with_retry (update )
313+ _send_update (update )
345314 if private_key :
346315 if not _wait_for_dnskey (name , dnskey ):
347316 logger .warning ("Knot CSK DNSKEY not visible after import for %s" , name )
@@ -394,6 +363,7 @@ def delete_zone(name):
394363def update_rrsets (
395364 domain_name , additions , modifications , deletions , deleted_records = None
396365):
366+ """Apply RRset changes via a single update attempt and surface errors."""
397367 from desecapi .models import RR , RRset
398368
399369 if not wait_for_zone (domain_name , attempts = 10 , interval_seconds = 0.2 ):
@@ -447,7 +417,7 @@ def update_rrsets(
447417
448418 def _apply_update ():
449419 try :
450- _send_update_with_retry (update , attempts = 2 , delay_seconds = 0.2 )
420+ _send_update (update )
451421 except Exception as exc :
452422 update_done ["error" ] = exc
453423
@@ -463,6 +433,7 @@ def _apply_update():
463433
464434
465435def import_zonefile_rrsets (name , rrsets ):
436+ """Import RRsets from a zonefile with one update attempt."""
466437 if not wait_for_zone (name , attempts = 60 , interval_seconds = 0.5 ):
467438 raise KnotException (f"Knot zone { name } not ready for updates" )
468439 record_count = 0
@@ -486,7 +457,7 @@ def import_zonefile_rrsets(name, rrsets):
486457 record_count ,
487458 type_preview ,
488459 )
489- _send_update_with_retry (update , attempts = 10 , delay_seconds = 1.0 )
460+ _send_update (update )
490461
491462
492463def ensure_soa_serial_min (
@@ -535,7 +506,7 @@ def ensure_soa_serial_min(
535506 attempts ,
536507 )
537508 update .replace (apex , rrset .ttl , "SOA" , soa_text )
538- _send_update_with_retry (update )
509+ _send_update (update )
539510 if delay_seconds :
540511 _sleep (delay_seconds )
541512 raise KnotException (f"Knot SOA serial for { name } still below { serial } " )
0 commit comments