Volans has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/349738 )
Change subject: DNS Discovery: add a check for the resolved address
......................................................................
DNS Discovery: add a check for the resolved address
Bug: T163364
Change-Id: Ia3023b7cbbe7baaf375120f1ed3e73d68528460b
---
M switchdc/lib/dnsdisc.py
M switchdc/stages/t00_reduce_ttl.py
M switchdc/stages/t05_switch_datacenter.py
M switchdc/stages/t09_restore_ttl.py
4 files changed, 65 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/operations/switchdc
refs/changes/38/349738/1
diff --git a/switchdc/lib/dnsdisc.py b/switchdc/lib/dnsdisc.py
index fb0b140..3bfe0b5 100644
--- a/switchdc/lib/dnsdisc.py
+++ b/switchdc/lib/dnsdisc.py
@@ -7,7 +7,7 @@
from switchdc.log import logger
-class DiscoveryTTL(object):
+class Discovery(object):
def __init__(self, *records):
nameservers = Remote.query('R:class = role::authdns::server')
self.resolvers = {}
@@ -18,26 +18,63 @@
self.resolvers[nameserver] = resolver
self.records = records
- def update(self, ttl):
+ def update_ttl(self, ttl):
+ """Update the TTL for all records.
+
+ Arguments:
+ ttl -- the value of the new TTL
+ """
# DRY-RUN handled by confctl
dnsdisc = '({regexp})'.format(regexp='|'.join(self.records))
logger.debug('Updating the TTL of {dnsdisc} to {ttl}
seconds'.format(dnsdisc=dnsdisc, ttl=ttl))
self.discovery.update({'ttl': ttl}, dnsdisc=dnsdisc)
- def check(self, expected):
+ def check_ttl(self, expected):
+ """Check the TTL for all records.
+
+ Arguments:
+ ttl -- the expected TTL value
+ """
logger.debug('Checking that TTL={ttl} for {records}.discovery.wmnet
records'.format(
ttl=expected, records=self.records))
- for nameserver, resolver in self.resolvers.items():
+ for record in self.resolve():
+ if not is_dry_run() and record.ttl != expected:
+ logger.error("Expected TTL '{expected}', got
'{ttl}'".format(expected=expected, ttl=record.ttl))
+ raise SwitchdcError(1)
+
+ def check_record(self, name, expected):
+ """Check that a record resolve to the expected IP.
+
+ Arguments:
+ name -- the record to check the resolution for.
+ expected -- the expected record to compare the resolution to.
+ """
+ logger.debug('Checking that {name}.discovery.wmnet records matches
{expected}'.format(
+ name=name, expected=expected))
+
+ # 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)
+
+ def resolve(self, name=None):
+ """Generator that yields the resolved records.
+
+ Arguments:
+ name -- optional record name to filter for.
+ """
+ for nameserver, resolver in self.resolvers.iteritems():
for record in self.records:
- answer = resolver.query('{}.discovery.wmnet'.format(record))
- message = '{ns}:{rec}: {ip} TTL {ttl}'.format(
- ns=nameserver, rec=record, ip=[r.address for r in
answer][0], ttl=answer.ttl)
- logger.debug(message)
- if is_dry_run():
+ if name is not None and record != name:
continue
- if answer.ttl != expected:
- logger.error("Expected TTL '{expected}', got
'{ttl}'".format(
- expected=expected, ttl=answer.ttl))
- raise SwitchdcError(1)
+ answer = resolver.query('{}.discovery.wmnet'.format(record))
+ message = '{ns}:{rec}: {ip} TTL {ttl}'.format(
+ ns=nameserver, rec=record, ip=answer[0].address,
ttl=answer.ttl)
+ logger.debug(message)
+ yield answer
diff --git a/switchdc/stages/t00_reduce_ttl.py
b/switchdc/stages/t00_reduce_ttl.py
index ece5409..e1b0020 100644
--- a/switchdc/stages/t00_reduce_ttl.py
+++ b/switchdc/stages/t00_reduce_ttl.py
@@ -1,14 +1,14 @@
import time
-from switchdc.lib.dnsdisc import DiscoveryTTL
+from switchdc.lib.dnsdisc import Discovery
__title__ = 'Reduce the TTL of all the MediaWiki read-write discovery records'
def execute(dc_from, dc_to):
"""Reduce the ttl on all appservers rw discovery entries."""
- ttl = DiscoveryTTL('appservers-rw', 'api-rw', 'imagescaler-rw')
- ttl.update(10)
+ ttl = Discovery('appservers-rw', 'api-rw', 'imagescaler-rw')
+ ttl.update_ttl(10)
# Verify
time.sleep(5)
- ttl.check(10)
+ ttl.check_ttl(10)
diff --git a/switchdc/stages/t05_switch_datacenter.py
b/switchdc/stages/t05_switch_datacenter.py
index 03a338e..306fd49 100644
--- a/switchdc/stages/t05_switch_datacenter.py
+++ b/switchdc/stages/t05_switch_datacenter.py
@@ -2,6 +2,7 @@
from switchdc.dry_run import is_dry_run
from switchdc.lib import mediawiki
from switchdc.lib.confctl import Confctl
+from switchdc.lib.dnsdisc import Discovery
from switchdc.log import logger
__title__ = 'Switch MediaWiki master datacenter and read-write discovery
records from {dc_from} to {dc_to}'
@@ -35,3 +36,9 @@
if obj.pooled and not is_dry_run():
logger.error('DNS discovery record {record} is still
pooled'.format(record=obj.key))
raise SwitchdcError(1)
+
+ # 4: verify that the IP of the records matches the expected one
+ dns = Discovery('appservers-rw', 'api-rw', 'imagescaler-rw')
+ dns.check_record('appservers-rw',
'appservers.svc.{dc_to}.wmnet'.format(dc_to=dc_to))
+ dns.check_record('api-rw', 'api.svc.{dc_to}.wmnet'.format(dc_to=dc_to))
+ dns.check_record('appservers-rw',
'rendering.svc.{dc_to}.wmnet'.format(dc_to=dc_to))
diff --git a/switchdc/stages/t09_restore_ttl.py
b/switchdc/stages/t09_restore_ttl.py
index bd238c4..dda6122 100644
--- a/switchdc/stages/t09_restore_ttl.py
+++ b/switchdc/stages/t09_restore_ttl.py
@@ -1,14 +1,14 @@
import time
-from switchdc.lib.dnsdisc import DiscoveryTTL
+from switchdc.lib.dnsdisc import Discovery
__title__ = 'Restore the TTL of all the MediaWiki read-write discovery records'
def execute(dc_from, dc_to):
"""Restore the original ttl on all appservers rw discovery entries"""
- ttl = DiscoveryTTL('appservers-rw', 'api-rw', 'imagescaler-rw')
- ttl.update(300)
+ ttl = Discovery('appservers-rw', 'api-rw', 'imagescaler-rw')
+ ttl.update_ttl(300)
# Verify
time.sleep(5)
- ttl.check(300)
+ ttl.check_ttl(300)
--
To view, visit https://gerrit.wikimedia.org/r/349738
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia3023b7cbbe7baaf375120f1ed3e73d68528460b
Gerrit-PatchSet: 1
Gerrit-Project: operations/switchdc
Gerrit-Branch: master
Gerrit-Owner: Volans <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits