Giuseppe Lavagetto has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/351670 )
Change subject: Dnsdisc: try multiple times on check_record
......................................................................
Dnsdisc: try multiple times on check_record
Bug: T164396
Change-Id: I4458751f4dd8c772ba64d8e8b06f37f06077840e
---
M switchdc/lib/dnsdisc.py
1 file changed, 18 insertions(+), 6 deletions(-)
Approvals:
Giuseppe Lavagetto: Looks good to me, approved
jenkins-bot: Verified
diff --git a/switchdc/lib/dnsdisc.py b/switchdc/lib/dnsdisc.py
index 9b84496..bacfdde 100644
--- a/switchdc/lib/dnsdisc.py
+++ b/switchdc/lib/dnsdisc.py
@@ -1,3 +1,5 @@
+import time
+
import dns.resolver
from switchdc import SwitchdcError
@@ -43,7 +45,7 @@
logger.error("Expected TTL '{expected}', got
'{ttl}'".format(expected=expected, ttl=record.ttl))
raise SwitchdcError(1)
- def check_record(self, name, expected):
+ def check_record(self, name, expected, attempts=3, sleep=3):
"""Check that a record resolve to the expected IP.
Arguments:
@@ -56,11 +58,21 @@
# Getting the expected record from the first resolver
address =
self.resolvers[self.resolvers.keys()[0]].query(expected)[0].address
- for record in self.resolve(name=name):
- if not is_dry_run() and record[0].address != address:
- logger.error("Expected IP '{expected}', got
'{address}'".format(
- expected=address, address=record[0].address))
- raise SwitchdcError(1)
+ for i in xrange(attempts):
+ logger.debug('Attempt {attempt} to check resolution for record
{record}'.format(attempt=i, record=name))
+ failed = False
+ for record in self.resolve(name=name):
+ if not is_dry_run() and record[0].address != address:
+ failed = True
+ logger.error("Expected IP '{expected}', got '{address}'
for record {record}".format(
+ expected=address, address=record[0].address,
record=name))
+
+ if not failed:
+ break
+ elif i != (attempts - 1): # Do not sleep after the last attempt
+ time.sleep(sleep)
+ else:
+ raise SwitchdcError(1)
def resolve(self, name=None):
"""Generator that yields the resolved records.
--
To view, visit https://gerrit.wikimedia.org/r/351670
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4458751f4dd8c772ba64d8e8b06f37f06077840e
Gerrit-PatchSet: 1
Gerrit-Project: operations/switchdc
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
Gerrit-Reviewer: Giuseppe Lavagetto <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits