1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

KCC: KCC object keeps lp and creds for live pings

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Douglas Bagnall 2015-06-10 15:40:43 +12:00 committed by Andrew Bartlett
parent 215f1c2c53
commit c182df9969

View File

@ -99,8 +99,8 @@ class KCC(object):
:param debug: Write verbosely to stderr. :param debug: Write verbosely to stderr.
"param dot_files: write Graphviz files in /tmp showing topology "param dot_files: write Graphviz files in /tmp showing topology
""" """
def __init__(self, unix_now, readonly=False, attempt_live_connections=True, def __init__(self, unix_now, readonly=False,verify=False, debug=False,
verify=False, debug=False, dot_files=False): dot_files=False):
"""Initializes the partitions class which can hold """Initializes the partitions class which can hold
our local DCs partitions or all the partitions in our local DCs partitions or all the partitions in
the forest the forest
@ -138,7 +138,6 @@ class KCC(object):
self.unix_now = unix_now self.unix_now = unix_now
self.nt_now = unix2nttime(unix_now) self.nt_now = unix2nttime(unix_now)
self.readonly = readonly self.readonly = readonly
self.attempt_live_connections = attempt_live_connections
self.verify = verify self.verify = verify
self.debug = debug self.debug = debug
self.dot_files = dot_files self.dot_files = dot_files
@ -347,10 +346,13 @@ class KCC(object):
logger.info("dsadn:%s\nncdn:%s\nneeded=%s:ro=%s:partial=%s\n" % logger.info("dsadn:%s\nncdn:%s\nneeded=%s:ro=%s:partial=%s\n" %
(dsadn, part.nc_dnstr, needed, ro, partial)) (dsadn, part.nc_dnstr, needed, ro, partial))
def refresh_failed_links_connections(self): def refresh_failed_links_connections(self, ping=None):
"""Ensure the failed links list is up to date """Ensure the failed links list is up to date
Based on MS-ADTS 6.2.2.1 Based on MS-ADTS 6.2.2.1
:param ping: An oracle function of remote site availability
:return: None
""" """
# LINKS: Refresh failed links # LINKS: Refresh failed links
self.kcc_failed_links = {} self.kcc_failed_links = {}
@ -385,15 +387,13 @@ class KCC(object):
# CONNECTIONS: Refresh failed connections # CONNECTIONS: Refresh failed connections
restore_connections = set() restore_connections = set()
if self.attempt_live_connections: if ping is not None:
DEBUG("refresh_failed_links: checking if links are still down") DEBUG("refresh_failed_links: checking if links are still down")
for connection in self.kcc_failed_connections: for connection in self.kcc_failed_connections:
try: if ping(connection.dns_name):
drs_utils.drsuapi_connect(connection.dns_name, lp, creds) # Failed connection is no longer failing\
# Failed connection is no longer failing
restore_connections.add(connection) restore_connections.add(connection)
except drs_utils.drsException: else:
# Failed connection still failing
connection.failure_count += 1 connection.failure_count += 1
else: else:
DEBUG("refresh_failed_links: not checking live links because we\n" DEBUG("refresh_failed_links: not checking live links because we\n"
@ -1125,7 +1125,7 @@ class KCC(object):
# Commit any modified repsFrom to the NC replica # Commit any modified repsFrom to the NC replica
n_rep.commit_repsFrom(self.samdb) n_rep.commit_repsFrom(self.samdb)
def merge_failed_links(self): def merge_failed_links(self, ping=None):
"""Merge of kCCFailedLinks and kCCFailedLinks from bridgeheads. """Merge of kCCFailedLinks and kCCFailedLinks from bridgeheads.
The KCC on a writable DC attempts to merge the link and connection The KCC on a writable DC attempts to merge the link and connection
@ -1143,7 +1143,7 @@ class KCC(object):
# site merge all the failure info # site merge all the failure info
# #
# XXX - not implemented yet # XXX - not implemented yet
if self.attempt_live_connections: if ping is not None:
debug.DEBUG_RED("merge_failed_links() is NOT IMPLEMENTED") debug.DEBUG_RED("merge_failed_links() is NOT IMPLEMENTED")
else: else:
DEBUG_FN("skipping merge_failed_links() because it requires " DEBUG_FN("skipping merge_failed_links() because it requires "
@ -1872,7 +1872,7 @@ class KCC(object):
return all_connected return all_connected
def intersite(self): def intersite(self, ping):
"""The head method for generating the inter-site KCC replica """The head method for generating the inter-site KCC replica
connection graph and attendant nTDSConnection objects connection graph and attendant nTDSConnection objects
in the samdb. in the samdb.
@ -1908,7 +1908,7 @@ class KCC(object):
all_connected) all_connected)
return all_connected return all_connected
self.merge_failed_links() self.merge_failed_links(ping)
# For each NC with an NC replica that "should be present" on the # For each NC with an NC replica that "should be present" on the
# local DC or "is present" on any DC in the same site as the # local DC or "is present" on any DC in the same site as the
@ -2507,7 +2507,8 @@ class KCC(object):
vertex_colors=vertex_colours) vertex_colors=vertex_colours)
def run(self, dburl, lp, creds, forced_local_dsa=None, def run(self, dburl, lp, creds, forced_local_dsa=None,
forget_local_links=False, forget_intersite_links=False): forget_local_links=False, forget_intersite_links=False,
attempt_live_connections=False):
"""Method to perform a complete run of the KCC and """Method to perform a complete run of the KCC and
produce an updated topology for subsequent NC replica produce an updated topology for subsequent NC replica
syncronization between domain controllers syncronization between domain controllers
@ -2599,17 +2600,29 @@ class KCC(object):
v.is_rodc_topology()} v.is_rodc_topology()}
self.plot_all_connections('dsa_forgotten_all') self.plot_all_connections('dsa_forgotten_all')
if attempt_live_connections:
# Encapsulates lp and creds in a function that
# attempts connections to remote DSAs.
def ping(self, dnsname):
try:
drs_utils.drsuapi_connect(dnsname, self.lp, self.creds)
except drs_utils.drsException:
return False
return True
else:
ping = None
# These are the published steps (in order) for the # These are the published steps (in order) for the
# MS-TECH description of the KCC algorithm ([MS-ADTS] 6.2.2) # MS-TECH description of the KCC algorithm ([MS-ADTS] 6.2.2)
# Step 1 # Step 1
self.refresh_failed_links_connections() self.refresh_failed_links_connections(ping)
# Step 2 # Step 2
self.intrasite() self.intrasite()
# Step 3 # Step 3
all_connected = self.intersite() all_connected = self.intersite(ping)
# Step 4 # Step 4
self.remove_unneeded_ntdsconn(all_connected) self.remove_unneeded_ntdsconn(all_connected)